Skip to content

Fix #1498: kotlin lib missing resource ID for OnClick annotation - #1540

Open
JantHsueh wants to merge 1 commit into
JakeWharton:masterfrom
JantHsueh:master
Open

Fix #1498: kotlin lib missing resource ID for OnClick annotation #1540
JantHsueh wants to merge 1 commit into
JakeWharton:masterfrom
JantHsueh:master

Conversation

@JantHsueh

Copy link
Copy Markdown

I am very happy to be involved in this project. If there is a need to change, I am willing to do my utmost.

I solved this problem Missing resource ID for OnClick annotation #1498 these days . Next, I will analyze the reasons and solutions.Please take a look ,thanks

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 use 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).

thanks

@JantHsueh JantHsueh changed the title Solve kotlin lib missing resource ID for OnClick annotation #1498 Fix:#1498 kotlin lib missing resource ID for OnClick annotation Jul 27, 2019
@JantHsueh JantHsueh changed the title Fix:#1498 kotlin lib missing resource ID for OnClick annotation Fix#1498: kotlin lib missing resource ID for OnClick annotation Jul 27, 2019
@JantHsueh JantHsueh changed the title Fix#1498: kotlin lib missing resource ID for OnClick annotation Fix #1498: kotlin lib missing resource ID for OnClick annotation Jul 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant