Android Studio 3.0 error: android-apt is incompati

2019-06-23 16:23发布

I'm new to Android development and got a legacy project. So I installed the newest version of Android Studio and opened it.

When I try to build it, I get this error:

Error:android-apt plugin is incompatible with the Android Gradle plugin.  Please use 'annotationProcessor' configuration instead.

I've trying the solutions shown in these thread, but it did not work.

I don't have any android-apt reference on my grandle build script.

Many of compile packages are shown as outdated. But when I follow Android's studio suggestion to update reference, I get errors saying the package was not found.

As I said, I'm new to Android Studio World, so I'm a little lost with all these stuff.

This is my build.gradle (Module: app):

apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'realm-android'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"


    defaultConfig {
        applicationId "xxxxxxxxxxxx"
        minSdkVersion 19
        targetSdkVersion 24
        versionCode 123
        versionName "1.2.3"
        manifestPlaceholders = [HOCKEYAPP_APP_ID: "xxxxxxxxxxxxxxxxxxxxx"]

        //For Test
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile('com.mikepenz:materialdrawer:4.6.4@aar') {
        transitive = true
    }

    //For Test
    androidTestCompile 'com.android.support:support-annotations:24.2.1'
    //noinspection GradleCompatible
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support.test:rules:0.5'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'

    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:cardview-v7:24.2.1'
    compile 'com.android.support:recyclerview-v7:24.2.1'
    compile 'com.android.support:support-v4:24.2.1'
    compile 'com.android.support:support-v13:24.2.1'
    compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
    compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
    compile 'com.squareup.okhttp3:okhttp:3.1.2'

    compile 'com.jakewharton:butterknife:7.0.1'

    compile 'com.p_v:flexiblecalendar:1.1.4'
    compile 'br.com.zbra:android-linq:1.0.1'

    compile 'com.google.android.gms:play-services-maps:9.4.0'

    compile 'com.github.PhilJay:MPAndroidChart:v2.1.6'
    compile 'com.cardiomood.android:android-widgets:0.1.1'
    compile 'com.github.thorbenprimke:realm-recyclerview:0.9.14'

    compile 'net.hockeyapp.android:HockeySDK:4.0.0'
}

This is my build.gradle (Project: MyApp):

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'me.tatarka:gradle-retrolambda:3.2.3'
        classpath "io.realm:realm-gradle-plugin:0.88.3"
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

1条回答
戒情不戒烟
2楼-- · 2019-06-23 16:53

The third party android-apt plugin is no longer supported. You should switch to the built-in annotation processor support, which has been improved to handle resolving dependencies lazily.

When using the Android plugin 3.0.0, you must add annotation processors to the processor classpath using the annotationProcessor dependency configuration, as shown below:

dependencies {
    ...
    annotationProcessor 'com.google.dagger:dagger-compiler:<version-number>'
}

Please read the full migration guide to Android Gradle Plugin 3.0.0 at https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html


Retrolambda is no longer needed. New Android Gradle Plugin supports Java 8 language features. Read more here.


Assuming you followed the migration guide the error is caused by old Realm plugin.

Realm plugin manages all Realm dependencies behind the scenes. This also means that its old version does not support new tools.

annotationProcessor configuration is first supported in Realm 2.2.0 as seen in the changelog:

Enhancements

  • Added support for the annotationProcessor configuration provided by Android Gradle Plugin 2.2.0 or later. Realm plugin adds its annotation processor to the annotationProcessor configuration instead of apt configuration if it is available and the com.neenbedankt.android-apt plugin is not used. In Kotlin projects, kapt is used instead of the annotationProcessor configuration (#3026).

Actually you have two options:

  • update your Realm to at least 2.2.0, or
  • go back to Android Gradle Plugin 2.3.3.
查看更多
登录 后发表回答