Butter Knife - Inject on Android lib

android, android-gradle-plugin, android-studio, butterknife, gradle

Solution

According to https://github.com/JakeWharton/butterknife

Library projects

To use Butter Knife in a library, add the plugin to your buildscript:

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

and then apply it in your module:

apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'

Now make sure you use R2 instead of R inside all Butter Knife annotations.

class ExampleActivity extends Activity {
  @BindView(R2.id.user) EditText username;
  @BindView(R2.id.pass) EditText password;
...
}

So it's now to possible to use `Butterknife` injects in Android libs.

Hope it will help

Problem

I work on Android Studio with Gradle. My issue is Non-constant Fields in Case Labels. When I use Butter Knife in Android lib, I get the following error: ``` tutuFragment.java:31: error: attribute value must be constant @InjectView(R.id.noContactTV) ``` Has anyone experienced the same issue, and if so, have a solution for it?

Original source