Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Butter Knife - Inject on Android lib

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?

like image 539
user3679598 Avatar asked May 27 '14 11:05

user3679598


2 Answers

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

like image 161
piotrek1543 Avatar answered Oct 19 '22 23:10

piotrek1543


Butterknife does not support library projects at this time, please refer to https://github.com/JakeWharton/butterknife/issues/100 for more informataion.

like image 30
keeganmccallum Avatar answered Oct 19 '22 23:10

keeganmccallum