butterknife
butterknife copied to clipboard
Missing resource ID for OnClick annotation
#974
perhaps related to that, it is able to generate correct _ViewBinding code for views but somehow not for OnClick
functions.
View view;
target.toolbar = Utils.findRequiredViewAsType(source, R.id.toolbar, "field 'toolbar'", Toolbar.class);
view = Utils.findRequiredView(source, com.mypackage.R.id.information_about, "field 'info' and method 'onClickAbout'");
target.info = view;
view7f0b006e = view;
view.setOnClickListener(new DebouncingOnClickListener() {
@Override
public void doClick(View p0) {
target.onClickAbout();
}
});
view = Utils.findRequiredView(source, 2131427440, "method 'onClickTermsAndCondition'");
view7f0b0070 = view;
view.setOnClickListener(new DebouncingOnClickListener() {
@Override
public void doClick(View p0) {
target.onClickTermsAndCondition();
}
});
It looks like it's still use an int reference rather than actual R
reference for OnClick
I'm using latest BK and kotlin 1.3.30
Thanks.
That's the default behavior. What's the problem? Please provide a sample which demonstrates the behavior.
Hi,
here is the repo to reproduce this issue
https://github.com/cooperkong/butterknifeR2issue
It crashes with ResourceNotFound
if launch Activity2
which is in a seperate module. however if I uncomment @BindView
in Activity2
it works.
class Activity2: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.lib2_layout)
ButterKnife.bind(this)
}
// @BindView(R2.id.textview2)
// lateinit var textView: TextView
@OnClick(R2.id.textview2)
fun donothing() {
}
}
Thanks.
i have the same issue
@JakeWharton I have uploaded the sample, can you please have a look see if it can be reproduced?
When I find time I will
On Tue, Apr 16, 2019, 7:26 PM WenChao Kong [email protected] wrote:
@JakeWharton https://github.com/JakeWharton I have uploaded the sample, can you please have a look see if it can be reproduced?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/JakeWharton/butterknife/issues/1498#issuecomment-483879937, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEERylgi6f9KUVvKg7AZBrpqPgPMM1ks5vhlw0gaJpZM4cu9WE .
I solved this problem these days and submitted a pull request. Next, I will analyze the reasons and solutions. Please take a look @JakeWharton
Reason: When using kotlin, for the same resource, if you do not use other annotations (eg: @bindview) before the event annotation (eg: @onclick), after generating view_binding.java, the Utils.findRequiredView() uses a raw integer not R reference.
When the merged resource is packaged, the static value of the R file has changed. So it leads "Missing resource ID".
Analysis: The annotation processing of kotlin generates a stub java file and processes the annotation according to the java file.But at this time ,Java file already using raw integer
My solution is to solve in the process() method, if it is the first time a raw integer, go through the R.java, find the corresponding static value in R.java, and use R reference replace it. If the second time is a raw integer, it will not be processed because the same resource will use the same Id(butterknife.compiler.Id.java).
@JantHsueh was your PR merged? Where can we see it? Or in which version the solution is available?
I have the same issue... Is there a solution besides add @BindView for the all @OnClick resource.