Dongfu He
Dongfu He

Reputation: 61

Proguard for Android Jetpack compose UI

My app will crash in release mode, it works find in debug mode. I suspect something should be kept in Proguard, but can't figure out what's wrong.

Fatal Exception: java.lang.NullPointerException androidx.compose.ui.text.platform.AndroidParagraphHelper_androidKt.createCharSequence (AndroidParagraphHelper_android.kt:48) androidx.compose.ui.text.platform.AndroidParagraphIntrinsics. (AndroidParagraphIntrinsics.android.kt:48) androidx.compose.ui.text.platform.AndroidParagraphIntrinsics_androidKt.ActualParagraphIntrinsics (AndroidParagraphIntrinsics_android.kt:38) androidx.compose.ui.text.ParagraphIntrinsicsKt.ParagraphIntrinsics (ParagraphIntrinsics.kt:38) androidx.compose.ui.text.ParagraphIntrinsicsKt.ParagraphIntrinsics$default (ParagraphIntrinsics.kt:38) androidx.compose.foundation.text.modifiers.ParagraphLayoutCache.setLayoutDirection (ParagraphLayoutCache.kt:38) androidx.compose.foundation.text.modifiers.ParagraphLayoutCache.b (ParagraphLayoutCache.kt:1) androidx.compose.foundation.text.modifiers.ParagraphLayoutCache.layoutWithConstraints-K40F9xA (ParagraphLayoutCache.kt:215) androidx.compose.foundation.text.modifiers.TextStringSimpleNode.measure-3p2s80s (TextStringSimpleNode.kt:215) androidx.compose.ui.node.LayoutModifierNodeCoordinator.measure-BRTryo0 (LayoutModifierNodeCoordinator.kt:11) androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.g (GraphicsLayerModifier.kt:1) androidx.compose.ui.node.LayoutModifierNodeCoordinator.measure-BRTryo0 (LayoutModifierNodeCoordinator.kt:11)

buildTypes {
    debug {
        minifyEnabled false
        kotlinOptions {
            freeCompilerArgs += [
                    '-Xopt-in=kotlin.RequiresOptIn'
            ]
        }
    }
    release {
        shrinkResources true
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        kotlinOptions {
            freeCompilerArgs += [
                    '-Xopt-in=kotlin.RequiresOptIn'
            ]
        }
    }
}

I have already add below to Proguard-rules.pro file.

# We supply these as stubs and are able to link to them at runtime
# because they are hidden public classes in Android. We don't want
# R8 to complain about them not being there during optimization.
-dontwarn android.view.RenderNode
-dontwarn android.view.DisplayListCanvas
 
-keepclassmembers class androidx.compose.ui.platform.ViewLayerContainer {
    protected void dispatchGetDisplayList(); }

-keepclassmembers class androidx.compose.ui.platform.AndroidComposeView {
    android.view.View findViewByAccessibilityIdTraversal(int); }

# Users can create Modifier.Node instances that implement multiple Modifier.Node interfaces,
# so we cannot tell whether two modifier.node instances are of the same type without using
# reflection to determine the class type. See b/265188224 for more context.
-keep,allowshrinking class * extends androidx.compose.ui.node.ModifierNodeElement


# Keep generic signature of Call, Response (R8 full mode strips signatures from non-kept items).
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
-keep,allowobfuscation,allowshrinking class retrofit2.Response
 
# With R8 full mode generic signatures are stripped for classes that are not
# kept. Suspend functions are wrapped in continuations where the type argument
# is used.
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation

Did I miss something?

Upvotes: 0

Views: 1438

Answers (0)

Related Questions