Fixing NoClassDefFoundError when using older APIs #1164
Merged
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.
Related to #1158
When using support library > 26.0.0 and android API < 23 if we try to create android.support.design.widget.TextInputLayout and call its addView method NoClassDefFoundError is thrown (for android.view.ViewStructure as it is not present in older APIs when trying to find the corresponding java method of a javascript method). This happens as in the method resolver we are trying to get the list of all class methods, but some of the methods accept android.view.ViewStructure parameter and this class is not present in older android APIs. As a result the getDeclaredMethods throws NoClassDefFoundError and the application crashes.
So catch for such error is added to the method getting all the method definitions and we are trying to get the exact method by name when needed.
To reproduce this you can set the following method as a StackLayout loaded event handler:
then set the supportVersion in the App_Resources/Android/app.gradle file to a version > 26.0.0:
and run the application on a device with API level < 23.
Here's a playground application with the code from above, so downloading it and setting the supportVersion should also reproduce the issue.