赞
踩
ButterKnife是一个专注于Android系统的View注入框架,以前总是要写很多findViewById来找到View对象,有了ButterKnife可以很轻松的省去这些步骤。使用ButterKnife对性能基本没有损失,因为ButterKnife用到的注解并不是在运行时反射的,而是在编译的时候生成新的class。
GitHub地址:https://github.com/JakeWharton/butterknife
利用了IOC的(Inverse of Controll)控制反转结构,2004年后改名为DI(dependency injection)依赖注入。目的是为了使类与类之间解耦合,提高系统的可扩展性和可维护性。越来越趋向于后端开发了。
书上教程为:
https://blog.csdn.net/anyong8888/article/details/101827415
会报错:Error:android-apt plugin is incompatible with the Android Gradle plugin. Please use 'annotationProce
解决:https://blog.csdn.net/l403040463/article/details/79166342
再报错:AS 3.3 The given artifact contains a string literal with a package reference 'android.support.v4.con
解决:https://blog.csdn.net/RichieZhu/article/details/86530472
(产生这个错误的原因是由于项目引用了AndroidX的依赖包,但是下面这两个依赖的内部是引用之前的 support 包实现的,因此产生矛盾。)
再报错:Static interface methods are only supported starting with Android N (–min-api 24)
解决:
在app module的build.gradle中添加:
android {
// ...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
// ...
}
(因为静态接口需要在Java 8 下才支持使用,所以我们要使用静态接口,就需要在app的build.gradle文件中配置声明,使用Java 8编译。)
步骤1.
在app module的build.gradle中添加:
android {
// ...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
// ...
}
步骤2.
在app module的build.gradle中添加:
implementation 'com.jakewharton:butterknife:10.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
更详细使用方式:
Butterknife 10.2.0版本组件化、模块化使用教程:
https://www.jianshu.com/p/b6990f643422
右键单击所需布局参数(例如,活动或片段中的R.layout.main),然后
Generate->Generate ButterKnife Injections
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。