material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.25k stars 3.06k forks source link

[MaterialAlertDialog] App freezing on dismiss() calling #4249

Open akelian opened 1 month ago

akelian commented 1 month ago

Description: App freezes when i'm calling dismiss() function from dialog which built with MaterialAlertDialogBuilder. In case of AlertDialog.Builder() it's okay. Also somehow problem appears only in debug build, while in release it works fine. In the moment of dismissing android system (not app) throw this excpetion:

Uncaught remote exception!  (Exceptions are not yet supported across processes.)
                            java.lang.RuntimeException: Unknown animation name: pathInterpolator
                                at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:194)
                                at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:158)
                                at android.view.animation.AnimationUtils.loadAnimation(AnimationUtils.java:139)
                                at com.android.server.wm.AppTransition.loadAnimationSafely(AppTransition.java:644)
                                at com.android.server.wm.AppTransition.loadAnimationAttr(AppTransition.java:614)
                                at com.android.server.wm.WindowStateAnimator.applyAnimationLocked(WindowStateAnimator.java:1467)
                                at com.android.server.wm.WindowState.removeIfPossible(WindowState.java:2315)
                                at com.android.server.wm.WindowState.removeIfPossible(WindowState.java:2236)
                                at com.android.server.wm.WindowManagerService.removeWindow(WindowManagerService.java:1928)
                                at com.android.server.wm.Session.remove(Session.java:193)
                                at android.view.IWindowSession$Stub.onTransact(IWindowSession.java:782)
                                at com.android.server.wm.Session.onTransact(Session.java:139)
                                at android.os.Binder.execTransactInternal(Binder.java:1154)
                                at android.os.Binder.execTransact(Binder.java:1123)

Expected behavior: The dialog window should be closed

Source code:

    private fun showLayerDialog() {
        val builder = MaterialAlertDialogBuilder(this)
        val geometryLayers = LayersManager.mmLayerList.filterIsInstance<GeometryObjectsLayer>()
        val namesArray = geometryLayers.map { it.name }
        val selectedElementPosition: Int = geometryLayers.indexOf(getCurrentSelectedLayer())

        builder
            .setTitle(getString(R.string.current_active_layer))
            .setCancelable(false)
            .setPositiveButton(R.string.ok) { dialog, _ ->
                dialog.dismiss()
            }
            .setSingleChoiceItems(
                namesArray.toTypedArray(), selectedElementPosition
            ) { _, which ->
                geometryLayers.forEachIndexed { position, layer ->
                    layer.currentSelected = position == which
                }
            }.show()
    }

gradle code:

    buildTypes {
        release {
            signingConfig = signingConfigs.getByName("debug")
            isDebuggable = false
            isMinifyEnabled = true
            isShrinkResources = true
        }

        debug {
            isMinifyEnabled = true
            isShrinkResources = true
            isDebuggable = true
        }

        all {
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }

proguard rules:

-dontwarn org.xmlpull.v1.**
-dontwarn org.kxml2.io.**
-dontwarn android.content.res.**

-keep class org.xmlpull.** { *; }
-keepclassmembers class org.xmlpull.** { *; }
-keep class androidx.navigation.ui.NavigationUI { *; }

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclassmembers class **.R$* {
       public static <fields>;
}

-dontwarn jsqlite.Callback
-dontwarn jsqlite.Database
-dontwarn org.bouncycastle.jsse.BCSSLParameters
-dontwarn org.bouncycastle.jsse.BCSSLSocket
-dontwarn org.bouncycastle.jsse.provider.BouncyCastleJsseProvider
-dontwarn org.conscrypt.Conscrypt$Version
-dontwarn org.conscrypt.Conscrypt
-dontwarn org.conscrypt.ConscryptHostnameVerifier
-dontwarn org.openjsse.javax.net.ssl.SSLParameters
-dontwarn org.openjsse.javax.net.ssl.SSLSocket
-dontwarn org.openjsse.net.ssl.OpenJSSE

Minimal sample app repro: Unfortunaly can't provide any sample

Android API version: api ver. 30

Material Library version: lib ver. 1.12.0

Device: Lenovo TB-X306X

hunterstich commented 1 month ago

Hey @akelian,

Could you try overriding your dialog's windowAnimationStyle and see if the issue goes away on your debug build? Like this:

<style name="Theme.App" parent="Theme.Material3.*">
  ...
  <item name="materialAlertDialogTheme">@style/ThemeOverlay.MyApp.MaterialAlertDialog</item>
</style>

<style name="ThemeOverlay.MyApp.MaterialAlertDialog" parent="ThemeOverlay.Material3.MaterialAlertDialog">
    <item name="android:windowAnimationStyle">@null</item>
</style>

Just trying to isolate the problem. I think it might be coming from an issue parsing the interpolator being used for our dialogs.

akelian commented 1 month ago

Hey @akelian,

Could you try overriding your dialog's windowAnimationStyle and see if the issue goes away on your debug build? Like this:

<style name="Theme.App" parent="Theme.Material3.*">
  ...
  <item name="materialAlertDialogTheme">@style/ThemeOverlay.MyApp.MaterialAlertDialog</item>
</style>

<style name="ThemeOverlay.MyApp.MaterialAlertDialog" parent="ThemeOverlay.Material3.MaterialAlertDialog">
    <item name="android:windowAnimationStyle">@null</item>
</style>

Just trying to isolate the problem. I think it might be coming from an issue parsing the interpolator being used for our dialogs.

Hi, For some reason I couldn't reproduce the bug. I had previously changed the MaterialBuilderDialog to AlertDialog.Builder to fix the issue, but now that I've changed it back the issue doesn't appear. So I can't say whether your suggestion will help or not.