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

Crash app after update to cordova android 10.1.0 #1432

Closed
1 task
Tumke opened this issue May 12, 2022 · 13 comments · Fixed by #1573
Closed
1 task

Crash app after update to cordova android 10.1.0 #1432

Tumke opened this issue May 12, 2022 · 13 comments · Fixed by #1573
Labels
Milestone

Comments

@Tumke
Copy link

Tumke commented May 12, 2022

Bug Report

App crash after update from cordova android 10.0.0 to 10.1.0 >

Problem

java.lang.RuntimeException: Unable to start activity ComponentInfo{/apId}: java.lang.NullPointerException: Attempt to invoke interface method 'int java.lang.CharSequence.length()' on a null object reference

What is expected to happen?

A starting app

What does actually happen?

The app crashes with java.lang.RuntimeException: Unable to start activity ComponentInfo{}: java.lang.RuntimeException: Failed to create webview.

Information

I can build the app without a problem, but after starting the app, the will app crash

Command or Code

Difficult to say, it is something in our app i guess. When i test it with a cordova testapp there is no problem. What changed in cordova android which is causing this problem?

Environment, Platform, Device

Android 9 >

Version information

cordova cli 11.0.0
build tools 30.0.3
min sdk 26
target sdk 30
I deinstalled all cordova plugins

Checklist

  • [ x] I searched for existing GitHub issues
  • [ x] I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@breautek breautek transferred this issue from apache/cordova May 18, 2022
@breautek
Copy link
Contributor

breautek commented May 18, 2022

What changed in cordova android which is causing this problem?

The most significant change is cordova-android@10 now uses AndroidX. But incompatibilties with AndroidX tends to manifest into build errors, not runtime errors.

I'd make sure that your PATH variable contains:

  • build tools 30.0.3 path. e.g: $ANDROID_HOME/build-tools/30.0.3
  • $ANDROID_HOME/cmdline-tools/6.0 (also make sure cmdline-tools are installed in Android SDK Tools.

Additionally, inside Android SDK Tools, I'd make sure you're up to date with the platform tools.

If none of these help, we will need to see a stacktrace to provide any other insights, or better... you will need to try to develop a minimal reproduction app.

@breautek breautek added the info-needed / awaiting response Further information is requested label May 18, 2022
@jonduttweiler
Copy link

Hey @Tumke, if you're running your app in a device connected via USB, you can try with adb logcat to check what happens

@stefano-8wave
Copy link

Hi, I've the same issue and crash with cordova-android ^10.1.2 minSdkVersion 25, target sdk 30. found with Firebase Crashlytics. it's a Samsung smartphone Galaxy S10 with android 12. I can't replicate the problem yet on my phone.

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.app/com.my.app.MainActivity}: java.lang.RuntimeException: Failed to create webview.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4035)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4201)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2438)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8663)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

@breautek
Copy link
Contributor

breautek commented Jul 16, 2022

Using proguard will cause issues like this. If you're using Proguard, you'll need to disable it or add exception rules (cordova has many APIs that are invoked by strings, used by plugins, therefore they cannot be obfuscated.

Some references:

Please confirm if you are using proguard and if so, if disabling it solves your issue. Due to the nature of plugin API calls, using proguard isn't really a supported configuration.

@Tumke
Copy link
Author

Tumke commented Aug 18, 2022

Yes, we are using Proguard. I completely disabled it, but the issue stays. I'm using a Samsung s20 with android 11.

I reproduced the error, and i see that it is different than when i started this issue (with and without proguard). I update the first post with the wright error message in logcat.

java.lang.RuntimeException: Unable to start activity ComponentInfo{/apId}: java.lang.NullPointerException: Attempt to invoke interface method 'int java.lang.CharSequence.length()' on a null object reference

@breautek
Copy link
Contributor

Thanks for confirming. At this point, we have cordova-android@11 is released and cordova-android@10 is no longer supported. So I'd ask you kindly if you can confirm the issue still presents itself when using cordova-android@11.

cordova-android@11 will require build tools version 32 and java 11. The most significant changes within the cordova code base is the introduction of the android splashscreens, honestly I'm not confident it will fix your issue, but we generally do not make backports.

Should your issue still persists, we will likely require a minimal reproduction app so that we can further investigate what is going on by tracing the error. A minimal reproduction app can be created by starting with a brand new test project, and slowly adding in plugins and bits of code until the issue reliably reproduces. This will help isolate the issue as well serve as a test case.

@Tumke
Copy link
Author

Tumke commented Aug 19, 2022

Hi, i solved the issue. <content src="index.html"/> was missing in the config.xml.

Thanks for your feedback. We will try to update to cordova 11!

@breautek
Copy link
Contributor

Hi, i solved the issue. <content src="index.html"/> was missing in the config.xml.

Thanks for your feedback. We will try to update to cordova 11!

Well that is certainly is interesting and if it fatally crashes during runtime due to the lack of the <content src> being specified, then I'd like to see some error feedback in the cordova tooling to make this obvious during build time, or at least make it at least default to index.html.

@Tumke
Copy link
Author

Tumke commented Aug 19, 2022

It looks like that running a cordova app on 10.0.0 < without <content src="index.html" /> was no problem, but now it is.

here is my complete error log:

2022-08-19 17:50:37.543 31994-31994/ E/AndroidRuntime: FATAL EXCEPTION: main
Process: , PID: 31994
java.lang.RuntimeException: Unable to start activity ComponentInfo{/.<app_name>}: java.lang.NullPointerException: Attempt to invoke interface method 'int java.lang.CharSequence.length()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3835)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4011)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2325)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'int java.lang.CharSequence.length()' on a null object reference
at java.util.regex.Matcher.reset(Matcher.java:256)
at java.util.regex.Matcher.(Matcher.java:167)
at java.util.regex.Pattern.matcher(Pattern.java:1027)
at org.apache.cordova.ConfigXmlParser.setStartUrl(ConfigXmlParser.java:173)
at org.apache.cordova.ConfigXmlParser.getLaunchUrl(ConfigXmlParser.java:53)
at org.apache.cordova.CordovaActivity.loadConfig(CordovaActivity.java:169)
at org.apache.cordova.CordovaActivity.onCreate(CordovaActivity.java:107)
at .<app_name>.onCreate(<app_name>.java:30)
at android.app.Activity.performCreate(Activity.java:8207)
at android.app.Activity.performCreate(Activity.java:8191)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3808)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4011)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2325)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

after checking "org.apache.cordova.ConfigXmlParser.getLaunchUrl(ConfigXmlParser.java:53)" on google i found this.
https://stackoverflow.com/questions/39931346/runtime-exception-when-running-cordova-app

Then i discoverd there was no <content src="index.html" /> our app.

@breautek breautek added bug and removed info-needed / awaiting response Further information is requested labels Aug 19, 2022
@breautek
Copy link
Contributor

Thanks for the stacktrace. The relevant part I think is:

Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'int java.lang.CharSequence.length()' on a null object reference
at java.util.regex.Matcher.reset(Matcher.java:256)
at java.util.regex.Matcher.(Matcher.java:167)
at java.util.regex.Pattern.matcher(Pattern.java:1027)
at org.apache.cordova.ConfigXmlParser.setStartUrl(ConfigXmlParser.java:173)
at org.apache.cordova.ConfigXmlParser.getLaunchUrl(ConfigXmlParser.java:53)
at org.apache.cordova.CordovaActivity.loadConfig(CordovaActivity.java:169)

This should be enough for a volunteer to create a patch.

@breautek breautek added this to the 11.0.1 milestone Aug 19, 2022
@xmetalmw
Copy link

xmetalmw commented Mar 20, 2023

Goodness, thank you for this thread. I've been bashing against that vague error for a few days after upgrading Cordova and trying to rebuild an older app. While I thought my config was fine, adding the <content src="index.html" /> was the fix I needed to build. I am on Cordova 11.1.0 and had Java 11 already, and just couldn't get past that. Phew, thanks again!

@breautek breautek modified the milestones: 11.0.1, 12.0.0 Mar 20, 2023
@breautek
Copy link
Contributor

Moving this from the 11.0.1 milestone to 12.0.0 milestone because master already has the major version bump.

@breautek
Copy link
Contributor

The proper solution is to ensure that your config.xml is to have a <content src="..." /> tag, as Cordova will expect that tag to exists, however starting with #1573 Cordova will default to index.html for the content src if the tag is missing, instead of it crashing on a null pointer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants