Fix #1498: kotlin lib missing resource ID for OnClick annotation #1540
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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