【问题标题】:Error Annotation Processors must be explicitly declared now现在必须显式声明错误注释处理器
【发布时间】:2017-11-03 17:26:19
【问题描述】:

突然我在执行应用程序时遇到错误。 我知道这里已经问过这个问题了:Annotation processors must be explicitly declared now

但是解决方案不能解决问题:(

这是我的 build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
    compileSdkVersion 26
    buildToolsVersion '27.0.0'
    aaptOptions {
        cruncherEnabled = true
    }
    defaultConfig {
        applicationId "com.freelance.crdzbird_dev.clarobadge"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        renderscriptTargetApi 22
        renderscriptSupportModeEnabled true
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    compile 'com.android.support:appcompat-v7:26.+'     
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:design:26.+'
    compile 'com.android.support:support-v4:26.+'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.github.javiersantos:MaterialStyledDialogs:2.1'
    annotationProcessor 'com.google.auto.value:auto-value:1.1'
    compile 'ai.api:libai:1.4.8'
    compile 'ai.api:sdk:2.0.7@aar'
    compile 'de.greenrobot:eventbus:2.4.0'
    compile 'io.mattcarroll.hover:hover:0.9.8'
    compile 'com.gjiazhe:MultiChoicesCircleButton:1.0'
    compile  "org.apache.logging.log4j:log4j-core:2.8"
    compile 'com.sackcentury:shinebutton:0.1.9'
    compile 'com.yalantis:contextmenu:1.0.7'
    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
    compile 'com.android.support:cardview-v7:26.0.0-alpha1'
    compile 'com.google.android.gms:play-services-maps:11.0.4'
    compile 'com.dlazaro66.qrcodereaderview:qrcodereaderview:2.0.2'
    compile 'me.samthompson:bubble-actions:1.3.0'
    compile 'com.google.android.gms:play-services:11.0.4'
    compile 'com.github.apl-devs:appintro:v4.2.2'
    compile 'com.github.PhilJay:MPAndroidChart:v3.0.2'
    compile 'com.google.firebase:firebase-messaging:10.2.1'
    testCompile 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'
repositories {
    mavenCentral()

任何人都知道如何解决此错误。我在谷歌搜索没有成功。

这是收到的错误

Error:Execution failed for task ':app:javaPreCompileDebug'.
> Annotation processors must be explicitly declared now.  The following dependencies on the compile classpath are found to contain annotation processor.  Please add them to the annotationProcessor configuration.
    - log4j-core-2.8.jar (org.apache.logging.log4j:log4j-core:2.8)
  Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior.  Note that this option is deprecated and will be removed in the future.
  See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.

【问题讨论】:

  • 即兴发挥...找出您的哪些依赖项依赖于log4j-core-2.8。联系这些依赖项的开发人员并要求他们修复他们对log4j-core-2.8 的使用。同时,在模块的build.gradle 文件中设置android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true
  • @CommonsWare 你是在暗示它是传递性的吗?似乎他明确地拉入了 log4j。
  • @Michael:哦,你是对的——我迷失了依赖海洋,错过了它。对不起!

标签: java android gradle annotations build.gradle


【解决方案1】:

那个用户的错误说这个注解处理器缺少auto-value-1.1.jar (com.google.auto.value:auto-value:1.1),答案是添加:

annotationProcessor 'com.google.auto.value:auto-value:1.1'

你的错误是log4j-core-2.8.jar (org.apache.logging.log4j:log4j-core:2.8),所以你认为答案是添加这个?

annotationProcessor 'com.google.auto.value:auto-value:1.1'

你已经逐字复制了!当然行不通!将注释处理器更改为您实际使用的处理器。


咳咳咳annotationProcessor 'org.apache.logging.log4j:log4j-core:2.8'

【讨论】:

  • 实际上,annotationProcessor 'org.apache.logging.log4j:log4j-core:2.8' 是我添加的第一件事,但结果是github.com/groovy/groovy-android-gradle-plugin/issues/145 gradle 结构与 apache 存在一些问题-log,所以最好的选择是将 gradle 依赖降级到 2.3.3
  • 你好像倒退了,不是吗?为什么在错误解决之前不使用旧版本的 Gradle?
  • 那是最好的临时替代方案
【解决方案2】:

请将此添加到您的 build.gradle

testImplementation('org.robolectric:robolectric:4.3.1') {
        // https://github.com/robolectric/robolectric/issues/5245
        exclude group: 'com.google.auto.service', module: 'auto-service'
    }

这样

在干净的项目和构建之后

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-17
    相关资源
    最近更新 更多