cordova-android
cordova-android copied to clipboard
Crash app after update to cordova android 10.1.0
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>/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
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.
Hey @Tumke, if you're running your app in a device connected via USB, you can try with adb logcat to check what happens
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)
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:
- https://stackoverflow.com/questions/57802791/unable-to-start-activity-componentinfo-java-lang-runtimeexception-failed-to-cre
- https://github.com/ionic-team/cordova-plugin-ionic-webview/issues/145
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.
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>/apId}: java.lang.NullPointerException: Attempt to invoke interface method 'int java.lang.CharSequence.length()' on a null object reference
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.
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!
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.
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/<appId> E/AndroidRuntime: FATAL EXCEPTION: main
Process: <appId>, PID: 31994
java.lang.RuntimeException: Unable to start activity ComponentInfo{<appId>/<appId>.<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.
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.
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.
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!
Moving this from the 11.0.1 milestone to 12.0.0 milestone because master already has the major version bump.
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 https://github.com/apache/cordova-android/pull/1573 Cordova will default to index.html for the content src if the tag is missing, instead of it crashing on a null pointer.