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

Brett Irvin
Brett Irvin
746 Points

More deprecated ButterKnife code

The ButterKnife library seems to have been updated again, and now the code provided to cut and paste is out of date.

Instead of @Bind, use @BindView. The @InjectView is deprecated, and so is @Bind.

4 Answers

Seth Kroger
Seth Kroger
56,413 Points

@benjakuben Yes, ButterKnife came out with a new major version this week. Version 8 renames the annotations again. (Dude, make up your mind already -_-) https://github.com/JakeWharton/butterknife/blob/master/CHANGELOG.md It also takes a bit more configuration to your build.gradle file to get it to work. The two lines of gradle code on the project's webpage aren't quite enough The full bit you need to add is listed in the repo's README https://github.com/JakeWharton/butterknife#download.

buildscript {
  repositories {
    mavenCentral()
   }
  dependencies {
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
  }
}

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

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

Are you adding that at the project level or module level. The compiler @ cannot seem to find the annotations. Seth Kroger

Seth Kroger
Seth Kroger
56,413 Points

The it works fine if it's all in the 'app' module. The README suggests to put the buildscript in the project level gradle file and the rest in the module. Gradle config blocks are additive, so it will work in either place.

Brett Irvin
Brett Irvin
746 Points

Thanks, Seth. I've got it up and running now--I think the issue was that I didn't have the expanded code for the build.gradle file.

Adan Olivares
Adan Olivares
4,749 Points

Thanks! I was doing it the old way too. I had just copied the one compile line and had trouble. I deleted that line and copied everything. Pasted outside the final curly brace in build.gradle

Not able to resolve @BindView in MainActivity

I think there is some issue with the code in BindView apply plugin: 'com.android.application' apply plugin: 'com.android.library' I think we can't use both

Seth Kroger
Seth Kroger
56,413 Points

Yes, your guess is correct. There are both instructions for using it with an app or a library that can be reused in other apps. You can't do both at the same time in the same module. Just go with the app instructions.