Android Studio升級到3.4遇到的問題總結


1、gradle需要升級。

  1)、project的build.gradle文件寫下如下代碼:

    buildscript {

    repositories {
    google()
    jcenter()
    }
    dependencies {
    classpath 'com.android.tools.build:gradle:3.4.0' //gradle版本號升級到高於3.4.0以上。
    }
    }  
  2)、gradle-wrapper.properties文件中寫上如下代碼:
     distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip   //此處最低要高於5.1.1
  3)、更新gradle版本可以通過配置的方式來更新,如下截圖:
    

2、關於buildToolsVersion值的設置。

  最小支持:28.0.3。各module都需要這么設置。

  統一去配置相關的值可以在project的build.gradle文件中編輯如下代碼:

  ext {
  minSdkVersion = 16
  targetSdkVersion = 26
  compileSdkVersion = 28
  buildToolsVersion = '28.0.3'
  sourceCompatibilityVersion = JavaVersion.VERSION_1_8
  targetCompatibilityVersion = JavaVersion.VERSION_1_8
  }

  在各module中引用的代碼如下:
  compileSdkVersion rootProject.ext.compileSdkVersion      //舉個例子。

3、添加依賴庫的關鍵詞需要更新。

compile

testCompile

androidTestCompile

             只能用於低版本                                                                         聲明的依賴包此模塊和其它依賴該模塊的其它模塊也可以使用                                              

api

testApi

androidTestApi 

            無版本限制 聲明的依賴包此模塊和其它依賴該模塊的其它模塊也可以使用

implementation

testImplementation

androidTestImplementation

           無版本限制,會使AS編譯速度更快 聲明的依賴包只限於模塊內部使用,不允許其他模塊使用。

4、Android Error: execution failed for task ':app:transformDexWithInstantRunSlicesApkForDebug'

  解決辦法: 
    File->Settings->Built,Execution,Deployment->Instant Run 
    不用勾選Enable Instant Run to hot swap code/resource changes on deploy(default enabled)

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM