Skip to content

Commit 725b3b5

Browse files
Enable R8/ProGuard for Android releases and upload mapping to Google Play
Agent-Logs-Url: https://github.com/richardthe3rd/cambridge-beer-festival-app/sessions/973c3cd3-1aef-488c-9251-0615981b4ff2 Co-authored-by: richardthe3rd <573334+richardthe3rd@users.noreply.github.com>
1 parent 9990ef0 commit 725b3b5

4 files changed

Lines changed: 58 additions & 18 deletions

File tree

.github/workflows/release-android.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ jobs:
145145
if-no-files-found: error
146146
retention-days: 7
147147

148+
- name: Upload mapping file (deobfuscation)
149+
if: matrix.build-type.name == 'appbundle'
150+
uses: actions/upload-artifact@v4
151+
with:
152+
name: android-mapping
153+
path: build/app/outputs/mapping/release/mapping.txt
154+
if-no-files-found: error
155+
retention-days: 7
156+
148157
# Create release with all artifacts
149158
create-release:
150159
needs: [version-info, build-artifacts]
@@ -237,11 +246,18 @@ jobs:
237246
name: android-aab
238247
path: artifacts/aab
239248

249+
- name: Download mapping file artifact
250+
uses: actions/download-artifact@v4
251+
with:
252+
name: android-mapping
253+
path: artifacts/mapping
254+
240255
- name: Upload to Google Play (Internal track)
241256
uses: r0adkll/upload-google-play@v1
242257
with:
243258
serviceAccountJsonPlainText: ${{ secrets.GOOGLE_PLAY_SERVICE_ACCOUNT_JSON }}
244259
packageName: ralcock.cbf
245260
releaseFiles: artifacts/aab/app-release.aab
261+
mappingFile: artifacts/mapping/mapping.txt
246262
track: internal
247263
status: completed

android/app/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ android {
4848
release {
4949
// Uses upload keystore when key.properties exists (CI), debug signing otherwise (local dev)
5050
signingConfig = keystorePropertiesFile.exists() ? signingConfigs.release : signingConfigs.debug
51-
minifyEnabled = false
52-
shrinkResources = false
51+
minifyEnabled = true
52+
shrinkResources = true
53+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
5354
}
5455
}
5556
}

android/app/proguard-rules.pro

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Flutter wrapper classes (wildcard covers all io.flutter.** subpackages)
2+
-keep class io.flutter.** { *; }
3+
4+
# Preserve Flutter plugin registrant (auto-generated)
5+
-keep class io.flutter.plugins.GeneratedPluginRegistrant { *; }
6+
7+
# Keep native methods
8+
-keepclassmembers class * {
9+
native <methods>;
10+
}
11+
12+
# Keep annotations used by Flutter plugins
13+
-keepattributes Signature
14+
-keepattributes *Annotation*
15+
-keepattributes InnerClasses
16+
-keepattributes EnclosingMethod
17+
18+
# Firebase SDKs bundle their own consumer ProGuard rules, but suppress missing-class
19+
# warnings for GMS classes that may be referenced but not included in all variants.
20+
-dontwarn com.google.android.gms.**
21+
22+
# Suppress warnings about missing optional classes
23+
-dontwarn androidx.lifecycle.**
24+
-dontwarn org.conscrypt.**
25+
-dontwarn org.bouncycastle.**
26+
-dontwarn org.openjsse.**

docs/tooling/android-release.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -691,10 +691,7 @@ storeFile=../../upload-keystore.jks
691691

692692
## Code Obfuscation & Optimization (ProGuard/R8)
693693

694-
Currently, ProGuard/R8 is **disabled** (`minifyEnabled = false`). This is intentional for initial releases to:
695-
- Simplify debugging
696-
- Avoid potential obfuscation issues with Flutter/Dart
697-
- Reduce initial build complexity
694+
Currently, ProGuard/R8 is **enabled** (`minifyEnabled = true`). This reduces app size and generates a deobfuscation mapping file that is automatically uploaded to Google Play Console, making crash analysis easier.
698695

699696
### Why Enable ProGuard/R8?
700697

@@ -791,20 +788,20 @@ retrace.sh -verbose mapping.txt obfuscated_trace.txt
791788

792789
### Recommendation for This App
793790

794-
**Current Status**: ✅ ProGuard/R8 disabled for simplicity
791+
**Current Status**: ✅ ProGuard/R8 enabled
795792

796-
**Recommended Approach**:
797-
1. **Initial releases**: Keep disabled (current setup)
798-
2. **After stability**: Enable on a beta track first
799-
3. **Test thoroughly**: Ensure all features work (especially URL launching, storage)
800-
4. **Monitor**: Watch for crashes in Play Console
801-
5. **Rollout**: Move to production if stable
793+
The mapping file is automatically uploaded to Google Play Console as part of the CI release workflow,
794+
enabling automatic deobfuscation of crash stack traces in the Play Console.
802795

803-
**When to Enable**:
804-
- App is stable in production
805-
- You want to reduce APK size (currently ~20-25 MB)
806-
- You're concerned about code security
807-
- You have time to debug potential issues
796+
**If you need to deobfuscate a stack trace locally:**
797+
798+
```bash
799+
# Mapping file location (after a release build)
800+
build/app/outputs/mapping/release/mapping.txt
801+
802+
# Use retrace to deobfuscate a crash trace:
803+
java -jar /path/to/retrace.jar mapping.txt obfuscated_trace.txt
804+
```
808805

809806
## Testing Before Release
810807

0 commit comments

Comments
 (0)