NullPointerException due Attempt to invoke virtual method 'android.os.IBinder android.view.SurfaceControl.getHandle()' on a null object reference
Asked Answered
S

4

16

Recently I did migration of my application to targetSdkVersion = 28. After publishing the updated app to Google Play I started to get very strange crash reports in Fabric.io: Crash report

Fatal Exception: java.lang.NullPointerException
Attempt to invoke virtual method 'android.os.IBinder android.view.SurfaceControl.getHandle()' on a null object reference
android.os.Parcel.createException (Parcel.java:1956)
android.os.Looper.loop (Looper.java:193)
android.app.ActivityThread.main (ActivityThread.java:6718)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:858)

This crash occurs only on Google devices(Pixel Series) with android Pie when app is opened by user from Play Store App, when opening from home screen everything works as expected. And there is no any trace to my code in crash report.

When I disable proguard everything works as expected

Satem answered 8/4, 2019 at 6:26 Comment(3)
Did you find an asnwer? I've the same crash SurfaceControl.getHandle() problem report here. But my error is not with only pixels, and I am not using proguardCloaca
This problem also happens on a Motorola Moto G7 (Android 9) where the app targets 29 (Android 10)Talcahuano
Any update about this issue?Wetmore
S
2

You can add this rules to you proguard-rules.pro:

-keep class android.view.**

Other than that, could you include some of your proguard configuration?

Schaal answered 3/8, 2021 at 5:7 Comment(2)
Could you explain what this does and how it solves the problem?Ld
It's basically tell proguard to keep the class that in the package android.view.** as is. So don't obfuscate itSchaal
G
0

We had a similar exception - only crashing on Pixel devices, too:

java.lang.NullPointerException: Attempt to invoke direct method 'void android.view.SurfaceControl.checkNotReleased()' on a null object reference
    at android.os.Parcel.createException(Parcel.java:2077)
    at android.os.Parcel.readException(Parcel.java:2039)
    at android.os.Parcel.readException(Parcel.java:1987)
    at android.app.IActivityTaskManager$Stub$Proxy.activityPaused(IActivityTaskManager.java:4489)
    at android.app.servertransaction.PauseActivityItem.postExecute(PauseActivityItem.java:64)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:177)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7356)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: android.os.RemoteException: Remote stack trace:
    at android.view.SurfaceControl.access$800(SurfaceControl.java:77)
    at android.view.SurfaceControl$Transaction.reparent(SurfaceControl.java:2429)
    at com.android.server.wm.SurfaceAnimator.transferAnimation(SurfaceAnimator.java:238)
    at com.android.server.wm.WindowContainer.transferAnimation(WindowContainer.java:1261)
    at com.android.server.wm.AppWindowToken.transferStartingWindow(AppWindowToken.java:1575)

We raised the targetSdkVersion and compileSdkVersion from 29 to 30 and the exception did not appear anymore.

Grobe answered 12/8, 2020 at 13:7 Comment(4)
I'm seeing the same issue on non-pixel devices (Samsung) using Android 10. My targetSdkVersion and compileSdkVersion are on 28.Ajaajaccio
I changed targetSdkVersion and compileSdkVersion from 28 to 30, but still get this crash on Android 10.Matland
@Matland same thing for me, but did you find a solution?Wetmore
I have the same problem on Google Pixels (79%) and Xiaomi (14%), android 12 only. compile 32, target 30Sultana
S
0

Update the target SDK version to 30 and upgrade the build tool version and Gradle version. Then clean and rebuild the project. If the problem is not fixed, we may need to look for more detailed log data for the application.

Seda answered 3/8, 2021 at 4:30 Comment(0)
P
-3

I myself was stuck in this issue for weeks until I found this

buildTypes {
        debug {
            debuggable true
            buildConfigField 'String', "GOOGLE_KEY", GOOGLE_API
            buildConfigField "boolean", "IS_DEBUG", "true"
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            minifyEnabled false
            shrinkResources false
        }
        release {
            debuggable false //This needs to be "true"
            buildConfigField "boolean", "IS_DEBUG", DEBUGABLE
            buildConfigField 'String', "GOOGLE_KEY", GOOGLE_API
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-optimize.pro'
            minifyEnabled false
            proguardFile PROGUARD_FILE
            shrinkResources false
        }
    }

Just change the debuggable in release to true.

Potshot answered 3/8, 2019 at 16:42 Comment(2)
Change debuggable false to true in release build type is not what any of us want to do.Satem
Yes I agree it is not the solution, but it will run the app. But I fixed the app crash by calling finish on current activity after calling startActivity for second activity. You can also check for the same for the screen where crash is occurring.Potshot

© 2022 - 2024 — McMap. All rights reserved.