尝试对已绑定的 ID 0 使用 @BindView

Attempt to use @BindView for an already bound ID 0

Android Studio 构建失败:

Attempt to use @BindView for an already bound ID 0 on 'mConnectionMessage'


Fragment.java:53: error: Attempt to use @BindView for an already bound ID 0 on 'mConnectionMessage'. 
    ImageView mConnectionImage;
              ^

这是导致问题的代码部分:

    @BindView(R2.id.display_discovery_state_icon)
    ImageView mConnectionImage;

简答:

下:

build.gradle

变化:

classpath 'com.android.tools.build:gradle:3.6.0'

至:

classpath 'com.android.tools.build:gradle:3.5.3'

长答案:

Android Studio 更新是问题的根本原因。

更新如下:

"To take advantage of the latest features, improvements, and security fixes, we strongly recommend that you update the Android Gradle plugin from the current version 3.5.3 to version 3.6.0 and Gradle to version 5.6.4. Release notes"

变化:

    classpath 'com.android.tools.build:gradle:3.5.3'

    classpath 'com.android.tools.build:gradle:3.6.0'

distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip

distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

仅通过手动进行上述更改(不一定 运行 更新)即可重现该问题。

注: 我可以在 windows 和 mac.

上重现问题并修复

升级butterknife版本到10.2.1

你用的是butternife吗?
就我而言,我升级到版本 10.2.1 (com.jakewharton:butterknife-gradle-plugin:10.2.1) 并且不再收到消息。

我正在使用 gradle 3.6.1.