错误:android-apt插件与Android Gradle插件不兼容。请改用“annotationProcessor”配置。

8
我收到了这个错误信息:Error:android-apt 插件与 Android Gradle 插件不兼容,请使用 "annotationProcessor" 配置代替。当我添加 butterknife 时出现了这个问题。请问我在依赖添加方面是否做错了什么?我应该使用哪种依赖来适配最新版本的 Android Studio?
下面是 build.gradle(module:app) 文件:
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.example.sony.welcomefilemanager"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'com.android.support:support-v4:26.1.0'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support:design:26.+'
    compile 'com.android.support:support-vector-drawable:26.+'
    compile 'com.android.support:design:26+'
    compile 'com.android.support:recyclerview-v7:26+'
    compile 'com.android.support:cardview-v7:26.+'
    compile 'com.jakewharton:butterknife:7.0.1'
    apt 'com.jakewharton:butterknife-compiler:8.0.1'
    testCompile 'junit:junit:4.12'
}

以下是build.gradle(项目)文件

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
3个回答

13

android-apt 插件已经被弃用。

从Android Gradle插件版本2.2开始,之前由 android-apt 提供的所有功能现在都可以在 Android 插件中使用。

  • 确保您正在使用 Android Gradle 2.2 插件或更高版本。
  • 从构建脚本中删除 android-apt 插件
  • 将所有(如果有)aptandroidTestApttestApt 依赖项更改为它们的新格式

并将 aptandroidTestApttestApt 更改为:dependencies { compile 'com.google.dagger:dagger:2.0' annotationProcessor 'com.google.dagger:dagger-compiler:2.0' } - Duong.Nguyen

5
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'
    defaultConfig {

从gradle中删除 apply plugin: 'android-apt'

像这样

apply plugin: 'com.android.application'
android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'
    defaultConfig {

1
我在 build.gradle(app 模块)文件中有这个代码块:apply plugin: 'com.neenbedankt.android-apt'。 我刚刚将它删除了,错误问题解决了。

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