102

After upgrading from 2.2 to 2.3 I see this warning

enter image description here

and when I try to compile the project I see this compilation error

enter image description here

How can i solve this issue without downgrading to a previous gradle version? Is there any update of android-apt that can solve this issue?

Bronx
  • 4,480
  • 4
  • 34
  • 44

5 Answers5

181

The android-apt plugin has been deprecated.
Check here for the migration guide:

As of the Android Gradle plugin version 2.2, all functionality that was previously provided by android-apt is now available in the Android plugin.

You can remove android-apt by following the migration guide to get the equivalent functionalities.

The important parts from the migration guide:

  • Make sure you are on the Android Gradle 2.2 plugin or newer.
  • Remove the android-apt plugin from your build scripts
  • Change all apt, androidTestApt and testApt dependencies to their new format:
dependencies {
   compile 'com.google.dagger:dagger:2.0'
   annotationProcessor 'com.google.dagger:dagger-compiler:2.0'
}

Also in the Android Gradle plugin there is an explicit check for this, which is what you are seeing:

using incompatible plugins for the annotation processing android-apt

Future Android Gradle plugin versions will not be compatible with the way android-apt works, which is the reason for that check.

straya
  • 5,002
  • 1
  • 28
  • 35
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • Thanks! I didn't know that apt was deprecated. – Bronx Mar 03 '17 at 09:38
  • 1
    And in the Android Gradle plugin Google has an explicit check for it, which is what you are seeing. Future Android Gradle versions will not be compatible with the way `android-apt` works, which is the reason for that check. – botteaap Mar 04 '17 at 09:00
  • where is the check? – ericn Apr 11 '17 at 09:44
  • I don't have any apt's but still get this warning. EDIT: Turns out it was realm – behelit Mar 28 '18 at 02:42
  • I didn't see NDROID-pt in my code anywhere, but getting error. What might be the issue? – Mubashar Apr 23 '18 at 13:07
  • I am having this same issue as well. Even I am not using any of things that belong to apt. but @Mubashar as he said I commented apply plug in for realm this worked for me. Now the code is compiling.but is that heppening. Can't we use realm? – Abdul Waheed Nov 15 '18 at 07:39
49

For me, I was having this error while using Contentful's Vault library which specifies that you include:

apply plugin: 'com.neenbedankt.android-apt'

and

compile 'com.contentful.vault:core:2.1.0'
apt 'com.contentful.vault:compiler:2.1.0'

What you need to do is DELETE apply plugin: 'com.neenbedankt.android-apt'

and then CHANGE:

compile 'com.contentful.vault:core:2.1.0'
apt 'com.contentful.vault:compiler:2.1.0'

to

annotationProcessor 'com.contentful.vault:compiler:2.1.0'
annotationProcessor 'com.contentful.vault:core:3.0.1'

You can always check https://github.com/contentful/vault for the latest versions

Ojonugwa Jude Ochalifu
  • 26,627
  • 26
  • 120
  • 132
15
  1. Remove apt plugin

  2. Change:

    apt -> compile

    testApt -> testAnnotationProcessor

    androidTestApt -> androidTestAnnotationProcessor

  3. In your build.gradle (app), add to defaultConfig:

vectorDrawables.useSupportLibrary = true

Octavian Ionel
  • 423
  • 6
  • 17
6

Piggybacking on @Gabriele Mariotti here since his answer is pretty spot on and implies this but doesn't state it. Gradle also does not suggest this as a valid option though it is as well. The testing equivalent for androidTestApt and testApt is androidTestAnnotationProcessor and testAnnotationProcessor.

Example:

testApt "com.google.dagger:dagger-compiler:$daggerVersion"
androidTestApt "com.google.dagger:dagger-compiler:$daggerVersion"

Should be changed to

testAnnotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
androidTestAnnotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
superuserdo
  • 1,637
  • 3
  • 21
  • 33
1

In case the annotation processor has arguments, one also might have to change this:

apt {
    arguments {
        KEY "VALUE"
    }
}

to this:

android {
    ...
    defaultConfig {
        ...
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ['KEY': 'VALUE']
            }
        }
    }
}
jox
  • 2,218
  • 22
  • 32