Butter Knife - Inject on Android lib

I am working on Android Studio with Gradle.

My problem. Inconsistent fields in case labels .

When I use Butter Knife in the 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 problem, and if so, do you have a solution?

+6
source share
5 answers

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

Library projects

To use Butter Knife in the library, add a 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 the entire Butter Knife annotation.

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

So, now you can use Butterknife for injection in Android libraries.

Hope this helps

+12
source

Butterknife does not currently support library projects; refer to https://github.com/JakeWharton/butterknife/issues/100 for more information.

+10
source

If your snippet is in an Android library project, check out this:

https://github.com/excilys/androidannotations/wiki/Library-projects

+1
source

The official github page has a solution: https://github.com/JakeWharton/butterknife

But when I followed the steps to configure my library project, I went to some problems, such as NullPointerException, functions marked with @onClick annotation were not called when viewing views, etc.

Then I changed something and finally did it. Please note the following: http://blog.csdn.net/ytzys/article/details/53243438

0
source

I had the same problem. I was getting this error when writing.

 @BindView(R.id.pager) ViewPager pager; 

or any other similar syntax for presentation.

The reason for getting this error was that the R file that was imported into my java file was from another package.

Now the question is, why was the imported R file from another package?

This was because I used my project as a library in another project. And when creating the library, I gave a different package name.

0
source

Source: https://habr.com/ru/post/969905/


All Articles