關於Android Studio 更新到3.0版本以後出現的一些問題以及解決方案
阿新 • • 發佈:2019-01-10
分析:尤其是採用butterknife工具的,採用新的Android Studio都會出現這樣的問題,我根據提示最後猜測原因可能是Android studio更新,然後gradle更新了,這樣的話可能使原來的android-apt工具跟不上節奏了,所以讓採用annotationProcessor工具。
解決方法:
1、修改project下的build.gradle當中的依賴
修改之前的程式碼:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'me.tatarka:gradle-retrolambda:3.2.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
修改之後的程式碼:
buildscript { repositories { jcenter() mavenCentral() google() } dependencies { classpath 'com.android.tools.build:gradle:3.0.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() maven { url "https://jitpack.io" } } } task clean(type: Delete) { delete rootProject.buildDir }
2、然後再修改Module.app裡的build.grade裡的配置
去除apply plugin: 'android-apt'
3、另外需要把之前apt方式的引用改下,例如:
apt 'com.jakewharton:butterknife-compiler:8.4.0' 改為 annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0' 這種方式。
按照上述方式修改之後,再次執行如果出現下圖情形,按照解決方案解決就行,如沒有請忽略
解決方案:關掉AAPT2即可 ,在Project/gradle.properties中新增 android.enableAapt2=false
android.enableAapt2=false
上述兩個問題都解決了之後,你以為一執行就完事了嘛,彆著急還有^_^也許還會出現下面這個問題,如果出現,就按照下面解決方案解決,如若沒有請忽略
報錯日誌:
Error:Execution failed for task ':CNKI:javaPreCompileDebug'.
> Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found to contain annotation processor. Please add them to the annotationProcessor configuration.
- lombok-1.16.12.jar (org.projectlombok:lombok:1.16.12)
Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior. Note that this option is deprecated and will be removed in the future.
See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.
解決方案:在Module.app裡的build.grade裡的android defaultCondig下新增,即可
javaCompileOptions {
annotationProcessorOptions { includeCompileClasspath = true }
}
以上就是在更新過AS新版以後遇到的問題以及解決方案^_^