一、gradle须要升级。html
1)、project的build.gradle文件写下以下代码:android
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版本能够经过配置的方式来更新,以下截图:
二、关于buildToolsVersion值的设置。api
最小支持:28.0.3。各module都须要这么设置。app
统一去配置相关的值能够在project的build.gradle文件中编辑以下代码:post
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 //举个例子。
三、添加依赖库的关键词须要更新。gradle
compileui testCompilegoogle androidTestCompilespa |
只能用于低版本 | 声明的依赖包此模块和其它依赖该模块的其它模块也能够使用 |
apicode testApi androidTestApi |
无版本限制 | 声明的依赖包此模块和其它依赖该模块的其它模块也能够使用 |
implementation testImplementation androidTestImplementation |
无版本限制,会使AS编译速度更快 | 声明的依赖包只限于模块内部使用,不容许其余模块使用。 |
四、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)