butterKnife学习——注解不起作用

在学习使用 butterKnife 框架遭遇问题:
AndroidStudio提示:

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

导致问题:

此时使用bindView完全不起效果

public class MainActivity extends AppCompatActivity
implements IWeatherInfoPage {
    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.btn_request_data)
    Button btnRequestData;
    @BindView(R.id.pgBar)
    ProgressBar progressBar;
    private static final String TAG = MainActivity.class.getSimpleName();
    @OnClick(R.id.btn_request_data)
    void onClick(View view){
        presenter.doLoadWeatherInfo("London");
    }

此时的Gradle配置为
project:

buildscript {
    repositories {
        mavenCentral() // add repository
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
       classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2'
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.7.0'
    }
}

app:

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'org.greenrobot.greendao' 
//apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'

 compile 'com.google.dagger:dagger:2.4'
 apt 'com.google.dagger:dagger-compiler:2.4'
    //java注解
compile 'org.glassfish:javax.annotation:10.0-b28'
compile 'com.orhanobut:logger:2.1.1'
compile 'org.greenrobot:greendao:3.2.2' // add library
compile 'com.facebook.stetho:stetho:1.5.0'//加入调试工具
compile 'com.facebook.stetho:stetho-okhttp3:1.5.0'//加入网络调试
compile 'com.jakewharton:butterknife:8.7.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0'

导致原因:

1.此时的Android Studio 更新为 2.3.3 version

  1. Annotation Processing 已经集成为Android studio gradle 插件,所以在使用这个版本的gradle或者更高加载,不需要再使用任何其他插件,所以

classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
apply plugin: 'com.neenbedankt.android-apt'

可以被移除,而:

apt 'com.google.dagger:dagger-compiler:2.4'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0'

此类需要apt插件的部分,都可以改为:

annotationProcessor 'com.google.dagger:dagger-compiler:2.4'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0'

此时,重新编译问题便解决了!如果想要开启关闭annotationProcessor
可以通过as设置:

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

感谢stackoverflow童鞋的帮助: https://stackoverflow.com/questions/42632662/android-studio-warning-using-incompatible-plugins-for-the-annotation-processing

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,909评论 25 708
  • 价量之秤 我对商业不太感兴趣,不敢遑论。 我在猜,如果在一个人的成长过程中,应该在一技之长上加价,还是在涉猎多个方...
    w小郭阅读 729评论 0 0
  • 等着什么事情发生,却不知道它会不会发生,这个过程是很有压力的,所以这个时候我是在受苦。
    小龙人玲阅读 154评论 0 0
  • 几种实现双向绑定的做法 发布者-订阅者模式(backbone.js): 一般通过sub, pub的方式实现数据和视...
    狗狗嗖阅读 2,122评论 0 1