ButterKnife 在AndroidStudio中的配置

来源:互联网 发布:如何解决域名劫持 编辑:程序博客网 时间:2024/05/16 09:52

ButterKnife 在AndroidStudio中的配置

  • ButterKnife是一个工具,可以通过注解的形式绑定Android中各种资源。例如: 控件, string, color, bitmap 等, 减少像 findViewById(), setOnClickListener()等重复代码, 让代码更加简洁, 同时也提高了程序员的开发效率.

一、在项目的gradle中配置

  • classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.8’

如:

// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript {    repositories {        jcenter()    }    dependencies {        classpath 'com.android.tools.build:gradle:2.0.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    }}allprojects {    repositories {        jcenter()    }}task clean(type: Delete) {    delete rootProject.buildDir}

二、在module中gradle中配置

apply plugin: ‘android-apt’

compile ‘com.jakewharton:butterknife:8.0.1’
apt ‘com.jakewharton:butterknife-compiler:8.0.1’

如:

apply plugin: 'com.android.application'apply plugin: 'android-apt'android {    compileSdkVersion 23    buildToolsVersion "25.0.2"    defaultConfig {        applicationId "com.example.wj.butterknifedemo"        minSdkVersion 15        targetSdkVersion 23        versionCode 1        versionName "1.0"    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }    }}dependencies {    compile fileTree(include: ['*.jar'], dir: 'libs')    testCompile 'junit:junit:4.12'    compile 'com.android.support:appcompat-v7:23.3.0'    compile 'com.android.support:support-v4:23.3.0'    compile 'com.jakewharton:butterknife:8.0.1'    apt 'com.jakewharton:butterknife-compiler:8.0.1'}
1 0