问题
I get the following error after I try to build my project:
Error:android-apt plugin is incompatible with the Android Gradle plugin. Please use 'annotationProcessor' configuration instead.
I tried to add annotationProcessor '.....'
after every implementation
but no success to get rid of the error.
This happens after upgrading android studio to the latest version ( 3.0 ).
Edit:
Adding includeCompileClasspath true
inside defaultConfig
doesn't help:
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
}
}
Any solutions?
回答1:
First of all, after upgrading there are a few changes to gradle.
Its important to upgrade to the latest gradle version to fix that.
That means that you need to add the proper version for your build gradle which is currently
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
}
the next step is to remove your android-apt
which is not longer needed.
its enough to have only apply plugin: 'com.android.application'
Onec you have done that, change your dependencies from
compile
to implementation
, apt
to annotationProcessor
and testCompile
to androidTestImplementation
If you have done that invalidate your cache and restart which is very important.
Then it should work.
You can find a working gradle file using the latest version at
app build.gradle and project build.gradle
p/s : For many people still use Realm old version,
Please update to latest version since old version still use "android-apt".
回答2:
you have to add annotationProcessorOptions
in app level gradle.
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.your.packagename"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// add below section
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
}
}
}
}
来源:https://stackoverflow.com/questions/46949518/android-studio-3-0-annotationprocessor