Until this point, testing on an Android phone was easy: plug it in, hit run, let Gradle install a debug build. But when I started preparing the real app bundle, I ran into the last stop on Android: bundle size and R8 minification.
A default libGDX + Kotlin build packages everything: the Java core, your code, the Kotlin stdlib, and four copies of the native C++ .so binaries for different CPU architectures. My first debug build was a heavy
28MB.
It needed to be smaller.
The 9.3MB build (and the instant crash)
In android/build.gradle I enabled the release flags that strip unused code and resources:
groovy
release {
minifyEnabled true
shrinkResources true
signingConfig signingConfigs.debug // For local release testing
}
The build ran fine. R8 trimmed the code, and the final .aab came down to
9.3MB.
I installed it, tapped the icon, and got an instant black screen and crash.
Why 3D engines break under minification
libGDX uses runtime reflection and a lot of JNI to talk to its C++ side (OpenGL, Box2D, audio).
With no rules, R8 looks at a class like com.badlogic.gdx.graphics.g3d.Model or the Scene2D layers, decides they're "unused" from static analysis alone, and renames or removes them. The build succeeds, but the phone throws a ClassNotFoundException the moment the 3D world starts. [
1]
Since this is a 3D game with a 2D UI on top, I had to write an explicit "keep" list to tell the optimizer what not to touch.
The working ProGuard rules
This is the proguard-rules.pro I landed on to keep the framework alive. It tells R8 to leave Kotlin metadata, native JNI bindings, 3D renderers, and UI skins alone:
pro
# 1. General & Performance Monitoring
-verbose
-dontwarn android.support.**
-dontwarn com.badlogic.gdx.backends.android.AndroidFragmentApplication
-keepattributes LineNumberTable,SourceFile,RuntimeVisibleAnnotations,AnnotationDefault
-renamesourcefileattribute SourceFile
# 2. Keep Kotlin Metadata (Crucial for Kotlin Game Logic)
-keep class kotlin.Metadata { *; }
-keep class kotlin.reflect.** { *; }
-keepclassmembers class **$WhenMappings { ; }
# 3. Protect Native C++ / JNI Bindings (Audio, Box2D, Graphics)
-keepclasseswithmembernames class * {
native ;
}
-keep class com.badlogic.gdx.backends.android.** { *; }
-keep interface com.badlogic.gdx.utils.Disposable { *; }
# 4. 3D Engine Packages (Shaders, Models, Environments)
-keep class com.badlogic.gdx.graphics.g3d.** { *; }
-keep class com.badlogic.gdx.graphics.g3d.attributes.** { *; }
-keep class com.badlogic.gdx.graphics.g3d.environment.** { *; }
-keep class com.badlogic.gdx.graphics.g3d.utils.** { *; }
# 5. 2D GUI (Scene2D, BitmapFonts, Colors, Skins)
-keep class com.badlogic.gdx.scenes.scene2d.** { *; }
-keep class com.badlogic.gdx.graphics.g2d.BitmapFont { *; }
-keep class com.badlogic.gdx.graphics.Color { *; }
-keep class com.badlogic.gdx.scenes.scene2d.ui.Skin$** { *; }
# 6. Project Specific Security (Launcher & Game Loop)
# IMPORTANT: Adjust 'your.package.name' to match your actual code package path!
-keep public class your.package.name.android.AndroidLauncher { *; }
-keep public class your.package.name.Main { *; }
-keep class your.package.name.** { *; } # Local code safety net
Takeaways
Keeping my own package (your.package.name.**) under a blanket keep rule meant my game screens and states wouldn't break, while R8 still stripped thousands of unused classes from the big libraries.
With this config the 9.3MB bundle runs fine. The game launches, the 2D UI scales right, and the 3D scenes load with no runtime penalty.
With the release pipeline stable and small, I can get back to fixing shader lighting and lightmap issues. More soon.