Setting Explict Annotation Processor

前端 未结 9 1221
自闭症患者
自闭症患者 2021-01-30 08:25

I am attempting to add a maven repository to my Android Studio project. When I do a Gradle project sync everything is fine. However, whenever I try to build my apk, I get this e

9条回答
  •  长发绾君心
    2021-01-30 08:47

    To fix the error, simply change the configuration of those dependencies to use annotationProcessor. If a dependency includes components that also need to be on the compile classpath, declare that dependency a second time and use the compile dependency configuration.

    For example:

    annotationProcessor 'com.jakewharton:butterknife:7.0.1'
    compile 'com.jakewharton:butterknife:7.0.1'
    

    This link describes it in detail: https://developer.android.com/studio/preview/features/new-android-plugin-migration.html#annotationProcessor_config

    Relevant snippet included for completeness.

    Use the annotation processor dependency configuration

    In previous versions of the Android plugin for Gradle, dependencies on the compile classpath were automatically added to the processor classpath. That is, you could add an annotation processor to the compile classpath and it would work as expected. However, this causes a significant impact to performance by adding a large number of unnecessary dependencies to the processor.

    When using the new plugin, annotation processors must be added to the processor classpath using the annotationProcessor dependency configuration, as shown below:

    dependencies { ... annotationProcessor 'com.google.dagger:dagger-compiler:' }

    The plugin assumes a dependency is an annotation processor if its JAR file contains the following file: META- INF/services/javax.annotation.processing.Processor. If the plugin detects annotation processors on the compile classpath, your build fails and you get an error message that lists each annotation processor on the compile classpath. To fix the error, simply change the configuration of those dependencies to use annotationProcessor. If a dependency includes components that also need to be on the compile classpath, declare that dependency a second time and use the compile dependency configuration.

提交回复
热议问题