diff --git a/android/app/build.gradle b/android/app/build.gradle index 7c40cc80..f5584983 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -73,13 +73,12 @@ android { jniDebuggable false minifyEnabled true shrinkResources true - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + // Use less aggressive ProGuard rules for native apps + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - // R8 full mode is enabled by default in newer AGP versions - - // Optimize native libraries + // Keep some debug info for crash reports ndk { - debugSymbolLevel 'NONE' + debugSymbolLevel 'SYMBOL_TABLE' } // Sign the release build diff --git a/android/app/proguard-rules.pro b/android/app/proguard-rules.pro index 39a969ba..2d33f31e 100644 --- a/android/app/proguard-rules.pro +++ b/android/app/proguard-rules.pro @@ -1,9 +1,9 @@ # Starship Android ProGuard Rules -# Keep SDL classes +# Keep SDL classes - critical for native integration -keep class org.libsdl.app.** { *; } -# Keep native methods +# Keep all native methods and JNI callbacks -keepclasseswithmembernames class * { native ; } @@ -28,24 +28,50 @@ # Keep DocumentFile for SAF -keep class androidx.documentfile.provider.DocumentFile { *; } -# Optimization settings --optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/* --optimizationpasses 5 +# Keep all classes that might be accessed via JNI +-keep class * { + public static ; + public static ; +} + +# Keep enums - often used by native code +-keepclassmembers enum * { + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +# Keep Serializable classes +-keepclassmembers class * implements java.io.Serializable { + static final long serialVersionUID; + private static final java.io.ObjectStreamField[] serialPersistentFields; + private void writeObject(java.io.ObjectOutputStream); + private void readObject(java.io.ObjectInputStream); + java.lang.Object writeReplace(); + java.lang.Object readResolve(); +} + +# Less aggressive optimization for native apps +-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*,!code/removal/advanced,!code/removal/simple +-optimizationpasses 3 -allowaccessmodification -dontpreverify -# Remove logging in release builds +# Don't remove logging completely - keep error logs for crash reports -assumenosideeffects class android.util.Log { public static boolean isLoggable(java.lang.String, int); public static int v(...); public static int i(...); public static int w(...); public static int d(...); - public static int e(...); } -# Keep line numbers for crash reports --keepattributes SourceFile,LineNumberTable +# Keep line numbers and source file for crash reports +-keepattributes SourceFile,LineNumberTable,*Annotation*,Signature -# Rename source file attribute to something shorter +# Rename source file attribute -renamesourcefileattribute SourceFile + +# Don't warn about missing classes that might be platform-specific +-dontwarn javax.** +-dontwarn java.awt.** +-dontwarn org.slf4j.**