android - ButterKnife 和 AnnotationProcessor

标签 android android-gradle-plugin butterknife

基于 ButterKnife lib,我升级到新版本8.5.1。我用过

compile 'com.jakewharton:butterknife:8.5.1'
  annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'

但它在我的 Android Studio 2.3 中警告我。 ButterKnife 不起作用(无法绑定(bind) View )。

Warning:Using incompatible plugins for the annotation processing: android-apt. This may result in an unexpected behavior.

我将 annotationProcessor 更改为 apt(我的 gradle 中有插件 apply plugin: 'com.neenbedankt.android-apt')并且它像旧版本一样工作,没有警告(我使用 apt 旧版本 8.4.0)

compile 'com.jakewharton:butterknife:8.5.1'
apt 'com.jakewharton:butterknife-compiler:8.5.1'

我认为 Android Studio 2.3 与 Annottaion 处理不兼容。我搜索并发现在 Android Studio 2.2 中启用注释处理器,但在 Android Studio 2.3 中找不到

Settings > Build, Execution, Deployment > Compiler > Annotation Processors

谁能解释一下这个问题?谢谢!

最佳答案

亲切的

//apply plugin: 'com.neenbedankt.android-apt'  <--remove this
apply plugin: 'com.jakewharton.butterknife'  <-- add this


dependencies {
    //classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'  <-- remove this
    classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1' <-- add this
}

然后在应用程序依赖项中

//butterknife

compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'

关于android - ButterKnife 和 AnnotationProcessor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42825172/

相关文章:

android - ButterKnife 不与 Jack 合作?

Android:RealViewSwitcher 不垂直滚动

android - CameraX 分析器不会在每一帧上运行

android - Gradle 同步阻止应用程序运行

android - 如何解决错误 : In project 'app' a resolved Google Play services library dependency

java - Butterknife 8.4.0 重新运行应用后找不到 View 。它得到一个 NullPointerException

java - 使用 Android 的 Mobile Vision API 扫描二维码

Android Studio 升级后无法导入模块

java - ProGuard 无法读取 android-support-v13.jar(;;;;;;!META-INF/MANIFEST.MF)(重复的 zip 条目 [android-support-v13.jar :])

java - 如何绑定(bind) Activity 中 NavigationView 中的 TextView