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)

 

猜你喜欢

转载自www.cnblogs.com/qynprime/p/10781419.html