Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Weather App (2015) Hooking Up the Model to the View Using Butter Knife for Views

I can't get ButterKnife to work.

I am doing everything it says on github and it still doesn't work. I also saw some answers here, but the method of adding it is changed again. The answers I saw are for 8.1.0 and this version is 8.2.8.

Can you post your build.gradle file where you're adding the dependencies and also the activity or fragment code where you are using Butter knife?

7 Answers

I meant to edit the bottom one..

In dependencies section of your module-level build.gradle file in addition to

apt 'com.jakewharton:butterknife-compiler:8.2.1'

you also need

compile 'com.jakewharton:butterknife:8.2.1'

Thanks, it didn't say that on github.

i can't get this to work even after trying to follow the instructions on the github. What should the build.gradle file contain? It is disappointing that the appropriate information is not included in the teacher's notes to make this module work correctly.

Can you post your build.gradle files, project and module?

I assume you probably figured it out by now, but I had the same problem, and here's what I did in case someone needs it. I fixed it by putting:

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

on the top of the build.gradle file. And then you need:

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

in your project build.gradle file, and

dependencies {
    compile 'com.jakewharton:butterknife:8.2.1'
    apt 'com.jakewharton:butterknife-compiler:8.2.1'

in your module build.gradle file.

apply plugin: 'com.android.application'
apply plugin: 'android-apt'
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.lakimens.weatherapp"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.squareup.okhttp3:okhttp:3.4.1'
    apt 'com.jakewharton:butterknife-compiler:8.2.1'
    compile 'com.jakewharton:butterknife:8.2.1'

}


// 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.1.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
}

Both files look correct to me. Can you post any error messages and also the code where you're using butter knife?

@BindView(R.id.TextView) TextView mTextView; Inside onCreate goes: ButterKnife.bind(this);

Yeah, Kourosh Raeen replied with the solution.