To take advantage of all the latest features (such as Instant Run), improvements and security fixes, we strongly recommend that you update the Android Gradle plugin to version 3* and Gradle to version 4.
遇到的问题:
WARNING: Configuration ‘compile’ is obsolete and has been replaced with ‘implementation’ and ‘api’.
解决方法:把Gradle Scripts文件夹中的build.gradle文件中的compile全部换成implementation
WARNING: The specified Android SDK Build Tools version (25.0.2) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.2.1.
解决方法:build.gradle中compileSdkVersion 版本号与buildToolsVersion不匹配。
改为匹配即可。
改为:buildToolsVersion ‘28.0.3’
编译时出现错误:
org.gradle.api.UncheckedIOException: Failed to capture snapshot of input files for task ‘:app:mergeDebugResources’ property ‘aapt2FromMaven’ during up-to-date check.
还不明白这个错误的原因是什么!
尝试修改: dependencies { classpath 'com.android.tools.build:gradle:3.2.1' (把3.2.1改为4.6,报错!入坑)
查看blog发现:
build.gradle里的版本和gradle-wrapper.properties里面的版本根本就不是一个玩意儿!build.gralde里的classpath 'com.android.tools.build:gradle:3.0.1’指的是Android Studio的gradle插件版本,而gradle-wrapper.properties里的distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip才是指定的gradle版本!
查看另一个成功的配置:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains("windows")) {
buildDir = "C:/tmp/${rootProject.name}/${project.name}"
}
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.android.sunshine"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
// TODO (10) Remove this dependency as we won't be needing it for the project until later
// Instrumentation dependencies use androidTestImplementation
// (as opposed to testImplementation for local unit tests run in the JVM)
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support:support-annotations:28.0.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
}
最后得到的文件是
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.android.example.favoritetoys"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
// TODO (7) Remove the ConstraintLayout dependency as we aren't using it for these simple projects
implementation 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains("windows")) {
buildDir = "C:/tmp/${rootProject.name}/${project.name}"
}
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
可以成功运行