cordova-android icon indicating copy to clipboard operation
cordova-android copied to clipboard

cordova-android@11 layout/splash_screen_view

Open cmartinezv opened this issue 3 years ago • 2 comments

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.(ViewGroup.java:8428) at android.widget.FrameLayout$LayoutParams.(FrameLayout.java:452) at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:380) at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:58) at android.view.LayoutInflater.rInflate(LayoutInflater.java:1129) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088) at android.view.LayoutInflater.inflate(LayoutInflater.java:686) at android.view.LayoutInflater.inflate(LayoutInflater.java:538) at android.view.LayoutInflater.inflate(LayoutInflater.java:485) at android.view.View.inflate(View.java:27024) at androidx.core.splashscreen.SplashScreenViewProvider$ViewImpl$_splashScreenView$2.invoke(SplashScreenViewProvider.kt:94) at androidx.core.splashscreen.SplashScreenViewProvider$ViewImpl$_splashScreenView$2.invoke(SplashScreenViewProvider.kt:93) at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) at androidx.core.splashscreen.SplashScreenViewProvider$ViewImpl.get_splashScreenView(SplashScreenViewProvider.kt:93) at androidx.core.splashscreen.SplashScreenViewProvider$ViewImpl.createSplashScreenView(SplashScreenViewProvider.kt:103) at androidx.core.splashscreen.SplashScreenViewProvider.(SplashScreenViewProvider.kt:52) at androidx.core.splashscreen.SplashScreen$Impl.setOnExitAnimationListener(SplashScreen.kt:305) at androidx.core.splashscreen.SplashScreen.setOnExitAnimationListener(SplashScreen.kt:185) at org.apache.cordova.SplashScreenPlugin.setupSplashScreen(SplashScreenPlugin.java:141) at org.apache.cordova.SplashScreenPlugin.onMessage(SplashScreenPlugin.java:113) at org.apache.cordova.PluginManager.lambda$postMessage$0(PluginManager.java:345) at org.apache.cordova.PluginManager$$ExternalSyntheticLambda0.accept(Unknown Source:8) at java.util.LinkedHashMap.forEach(LinkedHashMap.java:724) at java.util.Collections$SynchronizedMap.forEach(Collections.java:2698) at org.apache.cordova.PluginManager.postMessage(PluginManager.java:343) at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:161) at org.apache.cordova.CordovaActivity.loadUrl(CordovaActivity.java:234) 2022-09-21 10:08:38.566 6584-6584/io.cordova.hellocordova E/AndroidRuntime: at io.cordova.hellocordova.MainActivity.onCreate(MainActivity.java:40) at android.app.Activity.performCreate(Activity.java:8036) at android.app.Activity.performCreate(Activity.java:8016) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3581) 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)

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

cmartinezv avatar Sep 21 '22 08:09 cmartinezv

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

cellcrowd avatar Sep 22 '22 19:09 cellcrowd

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_HOME and PATH leads 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.

breautek avatar Sep 23 '22 01:09 breautek

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"/>

cellcrowd avatar Oct 04 '22 12:10 cellcrowd

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!

BenjaminPiette avatar Nov 09 '22 06:11 BenjaminPiette

closing since the reporter never answered and some other users found out their problem

jcesarmobile avatar Jan 08 '23 22:01 jcesarmobile

Solve it : https://github.com/apache/cordova-android/issues/1559#issuecomment-1565868979

nicolastinkl avatar May 28 '23 04:05 nicolastinkl

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 element in config.xml.

andreszs avatar Aug 29 '23 22:08 andreszs

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

dpogue avatar Aug 29 '23 22:08 dpogue