Android studio冲2.1版本升到3.1.2遇到好多问题,在这里做一下简单的总结,希望同道中人有则改之、无则加勉:
首先:
在安装完成后,需要对Gradle进行对应的升级,在升级过程中会遇到“Could not run build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-3.3-all.zip'.”这样的错误,重试了很多次都不行,后来重启电脑,这个问题就解决了,不得不感叹,还是重启大法好啊
其次:
在Android studio 3.0中build gradle的时候遇到“Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html”这样的错误提示,如图:
这里出现错误的原因是Android studio 3.0以后build.gradle中的关键词compile、testCompile、androidTestApi 将被implementation、testImplementation、androidTestImplementation等关键词替代,这里只需要将build.gradle中对应的关键词修改掉,重新编译即可。
然后:
在编译完成后,将app运行到模拟器上时,会遇到如下错误:
主要是因为我在工程里的module依赖了butterknife的jar包,而jar里面又用到了注解。在新的gradle版本里,需要写新的groovy代码来对每个引用注解的地方单独配置。而在以往的版本中,gradle会默认给每个module都依赖一个annotationProcess,导致很多多余的对annotationProcess的依赖。对应的解决方法如下:
在相应的module的gradle文件中,使用javaCompileOptions:
defaultConfig {
applicationId "com.breakloop.httpurlconnectiondemo"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//添加了javaCompileOptions
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath = true
}
}
}
然后重新编译运行到模拟器上即可