Android Studio 3.0 error: android-apt is incompatible

Android Studio 3.0 error: android-apt is incompatible

我是 Android 开发的新手,有一个遗留项目。所以我安装了最新版本的 Android Studio 并打开它。

当我尝试构建它时,出现此错误:

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

我尝试了这些 中显示的解决方案,但没有奏效。

我的 grandle 构建脚本中没有任何 android-apt 参考。

许多编译包显示为已过时。但是当我按照 Android 的工作室建议更新参考时,我收到错误消息说找不到包。

正如我所说,我是 Android Studio World 的新手,所以我对所有这些东西有点迷茫。

这是我的build.gradle(模块: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'
}

这是我的build.gradle(项目: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
}

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>'
}

请阅读 Android Gradle 插件 3.0.0 的完整迁移指南 https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html


不再需要 Retrolambda。新 Android Gradle 插件支持 Java 8 种语言功能。 Read more here.


假设您遵循了迁移指南,错误是由旧的 Realm 插件引起的。

Realm 插件在幕后管理所有 Realm 依赖项。这也意味着它的旧版本不支持新工具。

annotationProcessor 配置首先在 Realm 2.2.0 中得到支持,如 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).

实际上你有两个选择:

  • 将您的领域至少更新到 2.2.0,或者
  • 返回 Android Gradle 插件 2.3.3.