ButterKnife框架

Error:Execution failed for task :app:javaPreCompileVideoDebug.

> Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found to contain annotation processor. Please add them to the annotationProcessor configuration.

- butterknife-5.1.1.jar (com.jakewharton:butterknife:5.1.1)

Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior. Note that this option is deprecated and will be removed in the future.

See developer.android.com/r for more details.

然後掛了,更新版本吧


官方

配置

配置Butter Knife :

1. 安裝AS插件 Android ButterKnife Zelezny

2. 在項目中添加項目依賴

3. 開始使用註解

步驟1

首先打開AS, 打開 Settings -> Plugins -> 搜索Android ButterKnife Zelezny, 找到插件點擊安裝. 我下面的截圖是安裝之後的, 大家都懂, 不用多解釋. 重啟生效

分別找到Project Gradle配置文件和Modle Gradle配置文件.

在Project Gradle 配置文件中添加:

classpath com.neenbedankt.gradle.plugins:android-apt:1.8 // 添加這行

buildscript { repositories { jcenter() } dependencies { classpath com.android.tools.build:gradle:2.0.0 classpath com.neenbedankt.gradle.plugins:android-apt:1.8 // 添加這行 }}

再在 Module Gradle配置文件中添加:

apply plugin: com.neenbedankt.android-apt //添加這行

compile com.jakewharton:butterknife:8.2.1 //添加這行

apt com.jakewharton:butterknife-compiler:8.2.1 //添加這行

dependencies { compile fileTree(dir: libs, include: [*.jar]) testCompile junit:junit:4.12 compile com.android.support:appcompat-v7:24.0.0 compile com.jakewharton:butterknife:8.2.1 //添加這行 apt com.jakewharton:butterknife-compiler:8.2.1 //添加這行}

使用

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); }

滑鼠移到activity_main右擊


不同版本依賴方法不同

5.1.2

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.inject(this); }

7.0.1版本

compile com.jakewharton:butterknife:7.0.1

8.0.1版本

module:

apply plugin: com.neenbedankt.android-aptdependencies { compile fileTree(include: [*.jar], dir: libs) testCompile junit:junit:4.12 compile com.android.support:appcompat-v7:23.3.0 compile com.android.support:recyclerview-v7:23.3.0 //butterknife compile com.jakewharton:butterknife:8.0.1 apt com.jakewharton:butterknife-compiler:8.0.1}

project

dependencies { classpath com.android.tools.build:gradle:2.1.0 classpath com.neenbedankt.gradle.plugins:android-apt:1.8 // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }

8.5.1版本

module

apply plugin: com.jakewharton.butterknifedependencies { compile com.jakewharton:butterknife:8.5.1 annotationProcessor com.jakewharton:butterknife-compiler:8.5.1}

project

buildscript { repositories { mavenCentral() } dependencies { classpath com.jakewharton:butterknife-gradle-plugin:8.5.1 }}

推薦閱讀:

別再只用 Ctrl 複製粘貼,試試這幾個效率工具!
產品經理日常使用的工具會有哪些?
Anki有哪些值得推薦的詞庫和插件?
作為 IT 從業人員,你覺得有什麼工具大大提高了你的工作效率?
做谷歌SEO,我強烈推薦這兩款免費的工具

TAG:框架 | 安卓UI | 工具 |