原文:https://blog.csdn.net/lithiumyoung/article/details/80111111
Android Studio从2.3升级到3.1注意事项
-
项目根目录下的build.gradle
1.buildscript和allprojects的repositories中添加google()
2.dependencies中的classpath中将gradle版本修改为对应版本,如3.1.2buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.1.2' } } allprojects { repositories { google() jcenter() } }
- module目录下的build.gradle
-
1.删除buildToolsVersion。Android Studio3.0之后不需要再指定buildToolsVersion,每个版本的Android Gradle插件都有默认版本的构建工具,不删除只会报警告,但是这句指定构建版本的语句会被忽略
2.dependencies中 compile 替换为 implementation ,testCompile 替换为 testImplementation ,androidTestCompile 替换为 androidTestImplementationdependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:27.1.1' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' }
-
项目根目录下的gradle/wrapper文件夹下的gradle-wrapper.properties文件
修改 distributionUrl 的地址distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip
-
注意:多数教程中都没有提及这个文件,如果不改此处的地址,编译报错
Gradle DSL method not found: 'google()' Possible causes: The project 'app' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).