Android Studio 3.0错误:android-apt不兼容 [英] Android Studio 3.0 error: android-apt is incompatible

查看:183
本文介绍了Android Studio 3.0错误:android-apt不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Android开发的新手,并且有一个旧项目.因此,我安装了最新版本的Android Studio并将其打开.

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

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

我正在尝试这些

这是我的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-apt插件.您应该切换到内置的注释处理器支持,该支持已得到改进,可以延迟处理依赖关系.

使用Android插件3.0.0时,必须使用注释处理器依赖项配置将注释处理器添加到处理器类路径,如下所示:

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

请访问 https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html


不再需要Retrolambda.新的Android Gradle插件支持Java 8语言功能. 在此处了解更多信息.


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

Realm插件在后台管理所有Realm依赖项.这也意味着其旧版本不支持新工具.

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
}

解决方案

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.

这篇关于Android Studio 3.0错误:android-apt不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆