Android(安卓)Studio jcenter集成butterknife:8.x.0
16lz
2021-01-26
一、ButterKnife 简介
ButterKnife是一个专注于Android系统的View注入框架,可以减少大量的findViewById以及setOnClickListener代码,可视化一键生成。项目github地址:https://github.com/JakeWharton/butterknife
二、ButterKnife 优势
1、强大的View绑定和Click事件处理功能,简化代码,提升开发效率
2、方便的处理Adapter里的ViewHolder绑定问题
3、运行时不会影响APP效率,使用配置方便
4、代码清晰,可读性强
三、集成最新版本8.x.0<本篇使用的是v:8.7.0>
1.相比较7.x版本,8.x版本需要在项目的project 的build.gredle 文件中的dependencies标签下添加。
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
示例如下:
buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' }}allprojects { repositories { jcenter() }}task clean(type: Delete) { delete rootProject.buildDir}
2.在module的build.gredle 文件中的dependencies标签中添加
apply plugin: 'android-apt'
compile 'com.jakewharton:butterknife:8.x.0'
apt 'com.jakewharton:butterknife-compiler:8.x.0'
dependencies { // 默认配置 compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) // 默认配置 compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.android.support:design:25.3.1' testCompile 'junit:junit:4.12' // 集成butterknife apply plugin: 'android-apt' compile 'com.jakewharton:butterknife:8.7.0' apt 'com.jakewharton:butterknife-compiler:8.7.0'}
3.如果不添加apply plugin: 'android-apt',同步的时候会报如下错误,
Error:(27, 0) Gradle DSL method not found: 'apt()'Possible causes:- The project 'TransactionTest' may be using a version of Gradle that does not contain themethod.Open Gradle wrapper file
- The build file may be missing a Gradle plugin.Apply Gradle plugin
更多相关文章
- Android(安卓)selinux配置和用法
- Android(安卓)6.0之后无法使用apache的问题
- Android开发四年面试相关知识整理
- Android项目中使用javacv和javacpp的代码混淆配置
- android之按钮添加声音
- Android(安卓)Studio 1.5 配置AndroidAnnotations
- Ophone倒转屏幕自适应问题
- 《第一行代码——Android》pdf
- Android(安卓)Caused by: java.lang.IllegalArgumentException: