Hi everyone

I am sharing my experience with getting proguard to work with my project. Hope this may help someone. Without the proguard rules file the addons I am using in my project were not included in the release build.

Prerequisites:

  • Android build template must be installed
  • Android export preset configured

Add proguard to your build.gradle file

You can locate the build.gradle file in your project folder under android/build/build.gradle
Add the following code to android.buildTypes.release (the dot is shorthand for writing brackets)

shrinkResources true // Resource shrinking
minifyEnabled true // Code shrinking
proguardFiles getDefaultProguardFile(
'proguard-android.txt'),
'proguard-rules.pro'
// Uncomment the code below to include debug symbols in your release build
// ndk {
// debugSymbolLevel 'FULL' // Use 'SYMBOL_TABLE' if the file size for 'FULL' is too large
// }

Create the proguard-rules.pro file

Create the file under android/build/proguard-rules.pro and paste the following in.
The first 3 lines is important when you are using addons in your project. Without it the files will be excluded from the release build.

`
-keep class com.godot.** { *; }
-keep class org.godotengine.** { *; }
-keep class ** extends org.godotengine.godot.plugin.GodotPlugin { *; }

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
native <methods>;
}

-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
`
The template is from https://github.com/godotengine/godot/issues/43363#issuecomment-723443247

Tips

Google documentation refers to a folder named app in an Android Studio project. This folder is the same as android/build folder in Godot.

If you are getting a warning message when uploading your project to google console about uploading a deobfuscation file. Try uploading the mapping.txt file with your aab file. The mapping file can be found at android/build/build/outputs/mapping/release/mapping.txt

Google docs about deobfuscate:
https://support.google.com/googleplay/android-developer/answer/9848633?hl=en#zippy=%2Cupload-files-using-play-console%2Cnative-generate-a-debug-symbols-file%2Cjava-generate-a-proguard-mapping-file
and
https://developer.android.com/build/shrink-code