cordova-android
cordova-android copied to clipboard
cordova-android@11 layout/splash_screen_view
Bug Report
Problem
After upgrading my project to cordova-android11 I'm getting a RuntimeException only with Android API S after opening the app, though is working fine with API 33 and API 29.
What is expected to happen?
Show splashscreen and run app normally.
What does actually happen?
I'm getting this error:
--------- beginning of crash
2022-09-21 10:08:38.566 6584-6584/io.cordova.hellocordova E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.cordova.hellocordova, PID: 6584
java.lang.RuntimeException: Unable to start activity ComponentInfo{io.cordova.hellocordova/io.cordova.hellocordova.MainActivity}: android.view.InflateException: Binary XML file line #24 in io.cordova.hellocordova:layout/splash_screen_view: Failed to resolve attribute at index 0: TypedValue{t=0x2/d=0x7f0300df a=-1}
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3608)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3765)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:102)
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:2193)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7796)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:974)
Caused by: android.view.InflateException: Binary XML file line #24 in io.cordova.hellocordova:layout/splash_screen_view: Failed to resolve attribute at index 0: TypedValue{t=0x2/d=0x7f0300df a=-1}
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 0: TypedValue{t=0x2/d=0x7f0300df a=-1}
at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:827)
at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:8230)
at android.view.ViewGroup$MarginLayoutParams.
Information
This bug is resolved when I add a splash_screen_view.xml file myself in the layout folder, but after then API 29 doesn't work.
Command or Code
cordova create myApp2 cordova platform add android@11 cordova run android ( Android API S Simulator )
Environment, Platform, Device
cordova-android@11 Android API S Simulator
Checklist
- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version
- [x] I included all the necessary information above
I too am seeing crashes in the Google Play console related to InflateException, SynchronizedLazyImpl.getValue. All errors are pointing to android.view.InflateException at LayoutInflater.java:539. Looking further into the stack traces they seem splashscreen related. Devices suffering from this are running Android 6.0
By Android API S, I assume you mean API 31/Android 12.0 simulator.
I tried this with an empty cordova project with the default settings, as shown in the reproduction steps. and it isn't producing any RuntimeException for me.
I recommend to do the following:
- Ensure that Build Tools 32.0.0 is in your
PATH. Sometimes Cordova can intelligently find the correct build tools version, but other command line utilities will silently fail and produce bad builds by using an older build tools than what is expected for your compile target. - Ensure that Java 11 is being used (
JAVA_HOMEandPATHleads to a Java 11 environment) - Compile/target against API 32 (The cordova default in cordova-android@11)
If all that looks correct and you still have a reproducible error, then we may need a minimal reproduction app to move this issue along.
On my case, I was overriding the app's theme
<edit-config file="AndroidManifest.xml" target="/manifest/application/activity[@android:label='@string/activity_name']" mode="merge">
<activity android:theme="@style/AppTheme"></activity>
</edit-config>
Obviously the initial theme now needs to be a splash theme, which was causing my issues. To solve the issue, I removed above lines and replaced it with
<preference name="AndroidPostSplashScreenTheme" value="@style/AppTheme"/>
On my case, I was overriding the app's theme
<edit-config file="AndroidManifest.xml" target="/manifest/application/activity[@android:label='@string/activity_name']" mode="merge"> <activity android:theme="@style/AppTheme"></activity> </edit-config>Obviously the initial theme now needs to be a splash theme, which was causing my issues. To solve the issue, I removed above lines and replaced it with
<preference name="AndroidPostSplashScreenTheme" value="@style/AppTheme"/>
That was it, thanks!
closing since the reporter never answered and some other users found out their problem
Solve it : https://github.com/apache/cordova-android/issues/1559#issuecomment-1565868979
For anyone else using vanilla Cordova, the solution is to se the proper theme for AndroidManifest.xml in your config.xml as follows:
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<activity android:theme="@style/Theme.App.SplashScreen"></activity>
</edit-config>
This requires the XML namespace xmlns:android="http://schemas.android.com/apk/res/android" in your
For anyone else using vanilla Cordova [...]
You shouldn't need to change this for vanilla Cordova Android 12.x, because Theme.App.SplashScreen is the default value: https://github.com/apache/cordova-android/blob/e61e271f5bbb517a9598078f7a1ad7585bfe5f9c/templates/project/AndroidManifest.xml#L40