Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing NoClassDefFoundError when using older APIs #1164

Merged
merged 3 commits into from
Sep 3, 2018

Conversation

vtrifonov
Copy link
Contributor

@vtrifonov vtrifonov commented Aug 31, 2018

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:

load(args) {
    console.log("loaded");
    const context = args.object.android.getContext();
    const androidView = args.object.android;
    const til = new android.support.design.widget.TextInputLayout(context);
    const editText = new android.widget.EditText(context);
    const relativeLayout = new android.widget.RelativeLayout(context);
    const relativeLayoutParams = new android.widget.RelativeLayout.LayoutParams(android.widget.RelativeLayout.LayoutParams.MATCH_PARENT, android.widget.RelativeLayout.LayoutParams.MATCH_PARENT);
    relativeLayout.setLayoutParams(relativeLayoutParams);
    editText.setHint("TEST");

    console.log("this will crash on android api <23 and support 27.1.0+");
    til.addView(editText);

    androidView.addView(til);
}

then set the supportVersion in the App_Resources/Android/app.gradle file to a version > 26.0.0:

ext {
    supportVersion = "27.1.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.

@vtrifonov vtrifonov merged commit dff0fd3 into master Sep 3, 2018
@vtrifonov vtrifonov deleted the trifonov/fix-NoClassDefFoundError branch September 3, 2018 15:47
This pull request was closed.
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.

2 participants