ButterKnife

En cada aplicación Android, tienes que usar el método findViewById() para cada view en el layout que quieres usar en el código de tu aplicación.

El llamado a éste método se convierte en repetitivo y aquí es donde entra en escena Butter Knife.

¿Cómo agrego butterknife?

1) En nuestro archivo build.gradle(Project)

agregar la siguiente linea:

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

como quedaría:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
        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
}

2) En nuestro archivo build.gradle(app)

Agregar la siguiente linea arriba de todo.

apply plugin: 'com.neenbedankt.android-apt'

Agregar la siguiente línea en las depedencias

apt 'com.jakewharton:butterknife-compiler:8.4.0'
compile 'com.jakewharton:butterknife:8.4.0'

como quedaria:

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

android {
    compileSdkVersion 25
    buildToolsVersion "24.0.0"
    defaultConfig {
        applicationId "com.dev.myapplication"
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    mavenCentral()
}

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.0.0'
    testCompile 'junit:junit:4.12'
    apt 'com.jakewharton:butterknife-compiler:8.4.0'
    compile 'com.jakewharton:butterknife:8.4.0'

}

results matching ""

    No results matching ""