【问题标题】:Android Studio 3.0 error: android-apt is incompatibleAndroid Studio 3.0 报错:android-apt 不兼容
【发布时间】:2017-11-22 19:04:18
【问题描述】:

我是 Android 开发新手,并且有一个旧项目。于是我安装了最新版的Android Studio并打开了。

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

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

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

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

【问题讨论】:

  • 你用的是什么版本的android Studio?
  • 如标题所说:3.0.1
  • 你能附上项目build.gradle吗? (在你的根目录中)
  • 我用请求的信息编辑了帖子
  • 请查看 Android studio 3+ 的发行说明,您应该删除 retrolambda 和 apt 插件以支持内置支持developer.android.com/studio/releases/index.html

标签: android android-studio gradle realm-java android-apt


【解决方案1】:

不再支持第三方 android-apt 插件。您应该切换到内置的注解处理器支持,它已经过改进以处理延迟解析依赖项。

使用Android插件3.0.0时,必须使用annotationProcessor依赖配置将注解处理器添加到处理器类路径中,如下图:

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 所示:

增强功能

  • 添加了对 Android Gradle 插件 2.2.0 或更高版本提供的 annotationProcessor 配置的支持。 Realm 插件将其注解处理器添加到 annotationProcessor 配置而不是 apt 配置(如果它可用且未使用 com.neenbedankt.android-apt 插件)。在 Kotlin 项目中,使用 kapt 代替 annotationProcessor 配置 (#3026)。

其实你有两种选择:

  • 将您的 Realm 更新到至少 2.2.0,或
  • 返回 Android Gradle 插件 2.3.3。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多