Android Studio 3.0错误:android-apt不兼容。

5

我是Android开发新手,接手了一个旧项目。因此我安装了最新版本的Android Studio并打开了它。

当我尝试构建它时,我遇到了这个错误:

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

我尝试了这些线程中提供的解决方案,但都没有起作用。

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

许多编译包都显示为过时。但是当我按照Android Studio的建议更新引用时,出现错误提示找不到该包。

正如我所说,我对Android Studio世界还很陌生,所以对这些东西有点迷茫。

这是我的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'
}

这是我的 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
}

你正在使用哪个版本的Android Studio? - Valentin Baryshev
如标题所述:3.0.1 - Renan Vasconcelos
你能否附上项目的 build.gradle 文件?(在你的根目录下) - Valentin Baryshev
我已经编辑了帖子并提供了所请求的信息。 - Renan Vasconcelos
请查看Android Studio 3+的发布说明,您应该删除Retrolambda和APT插件,以支持内置功能。https://developer.android.com/studio/releases/index.html - Viktor Yakunin
1个回答

9

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语言特性。点击此处阅读更多。


假设您遵循了迁移指南,该错误是由旧的Realm插件引起的。
Realm插件管理所有Realm依赖项,这也意味着其旧版本不支持新工具。
changelog所示,annotationProcessor配置首次在Realm 2.2.0中得到支持:
增强功能: - 添加对Android Gradle Plugin 2.2.0或更高版本提供的annotationProcessor配置的支持。 如果可用且未使用com.neenbedankt.android-apt插件,则Realm插件将其注释处理器添加到annotationProcessor配置而不是apt配置中。 在Kotlin项目中,使用kapt代替annotationProcessor配置(#3026)。
实际上有两个选择: - 更新您的Realm至少为2.2.0 - 回到Android Gradle Plugin 2.3.3。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接