Closed jrgonzalezg closed 10 years ago
Yes this is not supported. This is a tradeoff between ease-of-use and what I tolerate as a sane API.
The only way to accomplish something like this is to allow string values like this:
@InjectView(name = "content_frame")
protected FrameLayout contentFrame;
The downside's to this are:
content_frame
ID that exists. Now the compilation will eventually fail because the generated code will become invalid.R
class to reference in the generated code, especially when you take into consideration the fact that you can use references to IDs that exist in libraries that you are referencing.value
and name
properties on each annotation which means you can write @InjectView Foo foo
and Butter Knife will have to fail the builder rather than javac
.Because of these facts, I have chosen not to support library projects.
One way that this could potentially be solved is to use a Gradle plugin rather than an annotation processor. I don't have the time to explore something like that for a few months though.
Jake, is there any way to support library projects in the future? I love Butterknife in my other projects, but I am currently working on one that uses a shared "library" codebase to make three apps that mostly do style and resource overrides. Having Butterknife supporting the library project would be amazing.
Jake, Shall we expect any improvements on this?
No. It's unlikely to ever be supported.
On Wed, Oct 7, 2015 at 2:37 PM Ponsuyambu Velladurai < notifications@github.com> wrote:
Jake, Shall we expect any improvements on this?
— Reply to this email directly or view it on GitHub https://github.com/JakeWharton/butterknife/issues/100#issuecomment-146288280 .
Aw. I would love to be using this for a library module I am working on for my company. The library serves as the base application project with all of the shared code between most of the apps my company makes.
As Butterknife won't support this, the next best option is probably Butterfork.
The lib version 7.0.1 is not support @InjectView(name = "content_frame")
What should we do ?
Butterfork is a solution. But I found another solution which used more easier. Ref ButterCookie.
That isn't enough information to be an actionable bug report.
On Tue, Jul 12, 2016 at 11:19 PM liuli notifications@github.com wrote:
I want to use it in libary with R2,but when i user the binded view ,report nullpointException,why?
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/JakeWharton/butterknife/issues/100#issuecomment-232245082, or mute the thread https://github.com/notifications/unsubscribe/AAEEEXUr4l4srMtocssWP53WzJG2IsHiks5qVFkrgaJpZM4Bg7MN .
The README instructions are somewhat misleading, the Gradle plugin for library projects only create a seperate R2 class. I believe you still need to include the Dagger compiler too as well right?
https://github.com/JakeWharton/butterknife/blob/master/sample/library/build.gradle
i followed the README, but i get an error (cannot resolve symbol 'R2'), did i miss something?!
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.jakewharton:butterknife-gradle-plugin:8.2.1'
classpath 'com.oguzbabaoglu:butterfork-plugin:2.0.0'
}
}
apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'com.oguzbabaoglu.butterfork-plugin'
apply plugin: 'android-apt'
dependencies {
compile 'com.jakewharton:butterknife:8.2.1'
apt 'com.jakewharton:butterknife-compiler:8.2.1'
// Dagger 2 and Compiler
compile 'com.google.dagger:dagger:2.0.1'
apt "com.google.dagger:dagger-compiler:2.0.1"
}
@mohamed-elwy See #690
Great to have now Butterknife supported in Library using R2.
I face a new issue, where if I have library A viewX, inheriting from library B viewY... I notice my butterknife injected in library B viewY is not working. (If I move viewY to library A, everything works).
Is this expected issue? or it shouldn't be an issue. i.e. my code issue somewhere.
In order to use Butterknife in an Instant App, you also have to use Butterknife gradle plugin to generate class R2.java .
I am having problem with ButterKnife injections on library projects. Whenever i try any view injection such as:
I get a compile time error: "error: attribute value must be constant" on the "R.id.content_frame". This occurs both using Android Studio and latest gradle plugin builds.
Any idea why?