Android 12 API 31 Splash Screen NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.drawable.Drawable.isProjected()

Viewed 611

I am implementing Splash Screen API on Android 12 following the article https://developer.android.com/about/versions/12/splash-screen-migration

I made Splash Screen API working but have crashes and relaunching android system on Android 8 and 9.

Here is code and logs:

Manifest.xml

<application
    android:name=".App"
    android:allowBackup="false"
    android:label="@string/app_name"
    android:icon="@mipmap/ic_launcher"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:theme="@style/AppTheme">

    <activity
        android:name=".ui.SplashActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.Splash"
        android:clearTaskOnLaunch="true"
        android:exported="true">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>

    <activity
       android:name=".ui.MainActivity"/>

</application>

styles.xml

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryVariant">@color/colorPrimaryVariant</item>
    <item name="colorOnPrimary">@color/white</item>
    <item name="colorSecondary">@color/colorSecondary</item>
    <item name="colorOnSecondary">@color/white</item>
    <item name="colorSurface">@color/white</item>
    <item name="colorError">@color/colorError</item>

    <item name="android:statusBarColor">@color/colorBackground</item>
    <item name="android:navigationBarColor">@color/colorBackground</item>
    <item name="android:windowLightStatusBar" tools:ignore="NewApi">true</item>
    <item name="android:windowLightNavigationBar" tools:ignore="NewApi">true</item>

    <item name="android:windowBackground">@color/colorBackground</item>
</style>

<style name="AppTheme.Splash" parent="Theme.SplashScreen">
    <item name="android:windowSplashScreenBackground" tools:ignore="NewApi">@color/colorSecondary</item>
    <item name="postSplashScreenTheme">@style/AppTheme.SplashScreen</item>
</style>

<style name="AppTheme.SplashScreen">
    <item name="android:statusBarColor">@color/colorSecondary</item>
    <item name="android:navigationBarColor">@color/colorSecondary</item>
    <item name="android:windowBackground">@drawable/splash</item>
    <item name="android:windowLightNavigationBar" tools:ignore="NewApi">false</item>
</style>

styles-v31.xml

<style name="AppTheme.Splash" parent="Theme.SplashScreen">
    <item name="android:windowSplashScreenBackground">@color/colorSecondary</item>
    <item name="android:windowSplashScreenAnimatedIcon">@drawable/ic_logo_white</item>
    <item name="postSplashScreenTheme">@style/AppTheme.SplashScreen</item>
</style>

logs

021-08-10 11:10:41.725 3296-3368/? E/AndroidRuntime: !@*** FATAL EXCEPTION IN SYSTEM PROCESS: android.anim
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.drawable.Drawable.isProjected()' on a null object reference
    at android.graphics.drawable.LayerDrawable.isProjected(LayerDrawable.java:417)
    at android.view.View.invalidateInternal(View.java:18121)
    at android.view.View.invalidate(View.java:18070)
    at android.view.View.setFrame(View.java:22656)
    at com.android.internal.policy.DecorView.setFrame(DecorView.java:928)
    at android.view.View.layout(View.java:22506)
    at android.view.ViewGroup.layout(ViewGroup.java:7190)
    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3456)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2916)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1964)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8721)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:988)
    at android.view.Choreographer.doCallbacks(Choreographer.java:765)
    at android.view.Choreographer.doFrame(Choreographer.java:700)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:967)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:216)
    at android.os.HandlerThread.run(HandlerThread.java:65)
    at com.android.server.ServiceThread.run(ServiceThread.java:44) 
2021-08-10 11:10:41.731 8297-8297/? E/ConfigUpdater: ignoring update request
2021-08-10 11:10:41.748 8297-8297/? E/ConfigUpdater: ignoring update request
2021-08-10 11:10:41.759 8297-8297/? E/ConfigUpdater: ignoring update request
2021-08-10 11:10:41.771 8297-8297/? E/ConfigUpdater: ignoring update request
2021-08-10 11:10:41.776 8297-8297/? E/ConfigUpdater: ignoring update request
2021-08-10 11:10:41.785 8297-8297/? E/ConfigUpdater: ignoring update request
2021-08-10 11:10:41.797 8297-8297/? E/ConfigUpdater: ignoring update request
2021-08-10 11:10:42.041 2848-2872/? E/SurfaceFlinger: Failed to remove layer from mapping - could not find matching layer
2021-08-10 11:10:42.058 2848-4219/? E/SurfaceFlinger: Failed to remove layer from mapping - could not find matching layer
2021-08-10 11:10:42.058 2848-2872/? E/SurfaceFlinger: Failed to remove layer from mapping - could not find matching layer
2021-08-10 11:10:42.064 2848-2872/? E/SurfaceFlinger: Failed to remove layer from mapping - could not find matching layer
2021-08-10 11:10:42.086 4318-4318/? E/IconDB: getIcon exception : android.os.DeadSystemException
2021-08-10 11:10:42.088 3023-3023/? E/vendor.samsung.hardware.biometrics.fingerprint@2.1-service: BiometricsFingerprintDeathRecipient::serviceDied - Fingerprint Sevice died
2021-08-10 11:10:42.089 3781-3781/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.google.android.gms.persistent, PID: 3781
    DeadSystemException: The system died; earlier logs will point to the root cause
2021-08-10 11:10:42.089 4365-4365/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.samsung.android.providers.context, PID: 4365
    DeadSystemException: The system died; earlier logs will point to the root cause
2021-08-10 11:10:42.092 4318-4318/? E/IconDB: getIcon exception : android.os.DeadSystemException
2021-08-10 11:10:42.092 4318-4474/? E/AndroidRuntime: FATAL EXCEPTION: launcher-loader
    Process: com.sec.android.app.launcher, PID: 4318
    DeadSystemException: The system died; earlier logs will point to the root cause
2021-08-10 11:10:42.094 6898-7502/? E/JavaBinder: *** Uncaught remote exception!  (Exceptions are not yet supported across processes.)
    DeadSystemException: The system died; earlier logs will point to the root cause
2021-08-10 11:10:42.096 4318-4318/? E/IconDB: getIcon exception : android.os.DeadSystemException
2021-08-10 11:10:42.098 4318-4474/? E/DiagMonLog: File exists.
2021-08-10 11:10:42.100 4318-4318/? E/IconDB: getIcon exception : android.os.DeadSystemException
2021-08-10 11:10:42.105 4318-4318/? E/IconDB: getIcon exception : android.os.DeadSystemException
2021-08-10 11:10:42.105 3023-3023/? E/bauth_FPBAuthService: ~FPBAuthService : set_cancel_flags and sleep 200ms
2021-08-10 11:10:42.109 4318-4318/? E/IconDB: getIcon exception : android.os.DeadSystemException
2021-08-10 11:10:42.111 3781-3781/? E/GCore-Chimera-Crash: Hit an exception while processing the UncaughtExceptionHandler:
DeadSystemException: The system died; earlier logs will point to the root cause
DeadSystemException: The system died; earlier logs will point to the root cause
2021-08-10 11:10:42.118 3781-3781/? E/BaseUncaughtHandler: Hit an exception while processing the UncaughtExceptionHandler. Original exception: 
    DeadSystemException: The system died; earlier logs will point to the root cause
2021-08-10 11:10:42.133 4318-4318/? E/DiagMonLog: File exists.
2021-08-10 11:10:42.140 4318-5369/? E/DiagMonLog: File exists.
2021-08-10 11:10:42.156 4781-5358/? E/ExceptionReporter: Unchecked exception happened while running task: bk[SearchService stop]
    DeadSystemException: The system died; earlier logs will point to the root cause
2021-08-10 11:10:42.169 4781-5358/? E/A: Encountered uncaught exception.
    DeadSystemException: The system died; earlier logs will point to the root cause
2021-08-10 11:10:42.243 7490-7490/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.android.vending, PID: 7490
    DeadSystemException: The system died; earlier logs will point to the root cause
2021-08-10 11:10:42.251 4781-4781/? E/ClientLoggingReceiver: Logging to Clearcut failed.
    com.google.android.gms.common.api.n: 8: 
        at com.google.android.libraries.s.a.a(SourceFile:7)
        at com.google.android.gms.common.api.internal.t.handleMessage(SourceFile:6)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at com.google.android.gms.h.c.c.c.b(SourceFile:1)
        at com.google.android.gms.h.c.c.c.dispatchMessage(SourceFile:1)
        at android.os.Looper.loop(Looper.java:216)
        at android.app.ActivityThread.main(ActivityThread.java:7266)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
2021-08-10 11:10:42.252 4781-4781/? E/ClientLoggingReceiver: Logging to Clearcut failed.
    com.google.android.gms.common.api.n: 20: The connection to Google Play services was lost due to service disconnection. Last reason for disconnect: Timing out service connection.
        at com.google.android.libraries.s.a.a(SourceFile:7)
        at com.google.android.gms.common.api.internal.t.handleMessage(SourceFile:6)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at com.google.android.gms.h.c.c.c.b(SourceFile:1)
        at com.google.android.gms.h.c.c.c.dispatchMessage(SourceFile:1)
        at android.os.Looper.loop(Looper.java:216)
        at android.app.ActivityThread.main(ActivityThread.java:7266)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
2021-08-10 11:10:42.253 4781-4781/? E/ClientLoggingReceiver: Logging to Clearcut failed.
    com.google.android.gms.common.api.n: 20: The connection to Google Play services was lost due to service disconnection. Last reason for disconnect: Timing out service connection.
        at com.google.android.libraries.s.a.a(SourceFile:7)
        at com.google.android.gms.common.api.internal.t.handleMessage(SourceFile:6)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at com.google.android.gms.h.c.c.c.b(SourceFile:1)
        at com.google.android.gms.h.c.c.c.dispatchMessage(SourceFile:1)
        at android.os.Looper.loop(Looper.java:216)
        at android.app.ActivityThread.main(ActivityThread.java:7266)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
2021-08-10 11:10:42.275 4781-4927/? E/AndroidRuntime: FATAL EXCEPTION: GoogleApiHandler
    Process: com.google.android.googlequicksearchbox:search, PID: 4781
    DeadSystemException: The system died; earlier logs will point to the root cause
2021-08-10 11:10:42.275 4781-4927/? E/A: Encountered uncaught exception.
    DeadSystemException: The system died; earlier logs will point to the root cause
2021-08-10 11:10:42.317 3023-3023/? E/TLC_BAUTH:   *****************************
2021-08-10 11:10:42.317 3023-3023/? E/TLC_BAUTH:   *** ERROR: TZ Session is not opened properly - Ignore
2021-08-10 11:10:42.317 3023-3023/? E/TLC_BAUTH:   *** Detected in BAuth_Cancel/1519()
2021-08-10 11:10:42.317 3023-3023/? E/TLC_BAUTH:   *****************************
2021-08-10 11:10:42.317 3023-3023/? E/bauth_FPBAuthService: ~FPBAuthService : BAuth_Cancel Fail
2021-08-10 11:10:42.324 3023-3023/? E/TLC_BAUTH:   *****************************
2021-08-10 11:10:42.324 3023-3023/? E/TLC_BAUTH:   *** ERROR: TZ Session is not opened properly - Ignore
2021-08-10 11:10:42.324 3023-3023/? E/TLC_BAUTH:   *** Detected in BAuth_Control_OP/1620()
2021-08-10 11:10:42.324 3023-3023/? E/TLC_BAUTH:   *****************************
2021-08-10 11:10:42.324 3023-3023/? E/bauth_FPBAuthService: check_opcode func_ret_val error = 29
2021-08-10 11:10:42.324 3023-3023/? E/(FPLOG): DeviceEnableInt 0 8 10 1
2021-08-10 11:10:42.325 3023-3023/? E/(FPLOG): 2.0.36.0 DeviceSetClock 0
2021-08-10 11:10:42.326 3606-3606/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.android.systemui, PID: 3606
    DeadSystemException: The system died; earlier logs will point to the root cause
2021-08-10 11:10:42.638 8094-8094/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.google.android.apps.tachyon, PID: 8094
    DeadSystemException: The system died; earlier logs will point to the root cause
    
    
    [          1628583042.657  8094: 8094 E/TY_com.google.android.libraries.processinit.finalizer.UncaughtExceptionHandlerProcessIn[005:262][8094] Encountered uncaught exception.
    
    
    [          1628583042.658  8094: 8094 E/TY_com.google.android.libraries.processinit.finalizer.UncaughtExceptionHandlerProcessIn[005:262][8094] java.lang.RuntimeException: android.os.DeadSystemException
    
    
    [          1628583042.658  8094: 8094 E/TY_com.google.android.libraries.processinit.finalizer.UncaughtExceptionHandlerProcessIn[005:262][8094] java.lang.RuntimeException: android.os.DeadSystemException
        at android.app.ContextImpl.unbindService(ContextImpl.java:1786)
        at android.content.ContextWrapper.unbindService(ContextWrapper.java:730)
        at lkb.e(Unknown Source:0)
        at lkb.b(PG:2)
        at ljb.handleMessage(PG:9)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:216)
        at android.app.ActivityThread.main(ActivityThread.java:7266)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
     Caused by: android.os.DeadSystemException
        at android.app.ContextImpl.unbindService(ContextImpl.java:1786) 
        at android.content.ContextWrapper.unbindService(ContextWrapper.java:730) 
        at lkb.e(Unknown Source:0) 
        at lkb.b(PG:2) 
        at ljb.handleMessage(PG:9) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:216) 
        at android.app.ActivityThread.main(ActivityThread.java:7266) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975) 
2021-08-10 11:10:42.693 8035-8073/? E/AndroidRuntime: FATAL EXCEPTION: GoogleApiHandler
    Process: com.google.android.apps.photos, PID: 8035
    DeadSystemException: The system died; earlier logs will point to the root cause
2021-08-10 11:10:44.211 3020-3294/? E/AT_Distributor: HandleResponseOnError: Calling regeistered ErrorCallback(err = 4)
2021-08-10 11:10:44.212 3020-3294/? E/AT_Distributor: RIL RESET!!! reconnect to RIL
2021-08-10 11:10:44.294 3006-3056/? E/storaged: getDiskStats failed with result NOT_SUPPORTED and size 0
2021-08-10 11:10:44.296 8422-8422/? E/IptablesRestoreController: [iptables debug]iptables-restore execute *filter
    :INPUT -
    -F INPUT
    :bw_INPUT -
    -A INPUT -j bw_INPUT
    :fw_INPUT -
    -A INPUT -j fw_INPUT
    :bw_VIDEOCALL_IN -
    -A INPUT -j bw_VIDEOCALL_IN
    COMMIT
2021-08-10 11:10:44.314 8422-8422/? E/IptablesRestoreController: [iptables debug]iptables-restore execute done, res : 0
2021-08-10 11:10:44.314 8422-8422/? E/IptablesRestoreController: [iptables debug]iptables-restore execute *filter
    :FORWARD -
    -F FORWARD
    :oem_fwd -
    -A FORWARD -j oem_fwd
    :fw_FORWARD -
    -A FORWARD -j fw_FORWARD
    :bw_FORWARD -
    -A FORWARD -j bw_FORWARD
    :tetherctrl_FORWARD -
    -A FORWARD -j tetherctrl_FORWARD
2 Answers

I got the same issue because I did not put any windowSplashScreenAnimatedIcon for API < 31. We need one and we can use the default one.

On your styles.xml file, edit like this:

<style name="AppTheme.Splash" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/colorSecondary</item>
    <item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher_round</item>
    <item name="postSplashScreenTheme">@style/AppTheme.SplashScreen</item>
</style>

I don't have any styles for API >= 31 and it seems to run this way.

One reason that can cause this problem is not putting the splash screen install as the first item in the onCreate lifecycle function. I've seen beginners attempting to put this at the top of the class file of their Activity or forgetting it all together.

 // Handle the splash screen transition.
 SplashScreen splashScreen = SplashScreen.installSplashScreen(this);
Related