Android ProGuard & R8 Rules for KMP
When generating release builds for Android in a Kotlin Multiplatform project, R8/ProGuard shrinks and obfuscates bytecode to reduce APK/AAB size. To ensure Appxiom classes, reflection hooks, line numbers, and coroutine continuations are preserved for accurate stack trace mapping, add the following keep rules.
Step 1: Add Keep Rules to proguard-rules.pro
Open your Android module's ProGuard file (typically composeApp/proguard-rules.pro or androidApp/proguard-rules.pro) and add:
# Preserve Appxiom SDK classes and annotations
-keep class tech.appxiom.** { *; }
-keepclassmembers class * {
@tech.appxiom.android.core.annotation.AX *;
}
-keepclassmembers class androidx.lifecycle.** {
*;
}
# Preserve line numbers and source file names for readable stack trace mapping
-keepattributes SourceFile,LineNumberTable
-renamesourcefileattribute SourceFile
-keepattributes *Annotation*,Signature,InnerClasses,EnclosingMethod
# Keep Kotlin Coroutine continuations and annotations
-keepattributes RuntimeVisibleAnnotations,RuntimeVisibleParameterAnnotations
-keepclassmembers class kotlinx.coroutines.** { *; }
Step 2: Reference ProGuard in build.gradle.kts
Ensure your release build type block in composeApp/build.gradle.kts (or androidApp/build.gradle.kts) references proguard-rules.pro:
android {
buildTypes {
release {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
}
Preserving mapping.txt for Crash De-obfuscation
Every release build produces a unique mapping.txt file located at:
composeApp/build/outputs/mapping/release/mapping.txt
Always back up this file before running ./gradlew clean or building a new version. For automated Gradle backup tasks and retrace workflows, see Release Symbolication.
Next Steps
Now verify that issues and events are reaching the dashboard using Verify Integration.