Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 3.0 annotationProcessor [duplicate]

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?

like image 666
Marian Pavel Avatar asked Oct 26 '17 08:10

Marian Pavel


2 Answers

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".

like image 66
Emanuel S Avatar answered Nov 15 '22 16:11

Emanuel S


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
        }
    }
 }
}
like image 2
Akash Patel Avatar answered Nov 15 '22 15:11

Akash Patel