-
Notifications
You must be signed in to change notification settings - Fork 4
[FSSDK-11888] fix: update ProGuard rules for AGP 8+ and R8 compatibility #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
a41402f
69a7edc
f16c364
71a352d
157fb27
2b33948
925ae04
0868921
2507f36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,4 +170,4 @@ jobs: | |
channel: 'stable' | ||
architecture: x64 | ||
- run: flutter pub get | ||
- run: flutter test | ||
- run: flutter test | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
name: Minification Compatibility Test | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
minification_compatibility_test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Flutter | ||
uses: subosito/flutter-action@v2 | ||
with: | ||
channel: 'stable' | ||
architecture: x64 | ||
cache: true | ||
|
||
- name: Setup Java | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '17' | ||
|
||
- name: Configure Gradle JVM options | ||
run: | | ||
mkdir -p ~/.gradle | ||
cat > ~/.gradle/gradle.properties << 'EOF' | ||
# Increase heap size for CI builds | ||
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1g -XX:+HeapDumpOnOutOfMemoryError | ||
org.gradle.daemon=true | ||
org.gradle.parallel=true | ||
org.gradle.configureondemand=true | ||
android.enableJetifier=true | ||
android.useAndroidX=true | ||
EOF | ||
- name: Configure Android build options | ||
run: | | ||
cat >> example/android/gradle.properties << 'EOF' | ||
# Memory optimization for CI | ||
org.gradle.jvmargs=-Xmx3g -XX:MaxMetaspaceSize=512m | ||
android.enableJetifier=true | ||
android.useAndroidX=true | ||
EOF | ||
- name: Install dependencies | ||
run: | | ||
flutter pub get | ||
cd example && flutter pub get | ||
- name: Create ProGuard rules for example app | ||
run: | | ||
cat > example/android/app/proguard-rules.pro << 'EOF' | ||
# Example app ProGuard rules for minification testing | ||
# Keep example app classes | ||
-keep class com.optimizely.optimizely_flutter_sdk_example.** { *; } | ||
# Keep Flutter classes | ||
-keep class io.flutter.app.** { *; } | ||
-keep class io.flutter.plugins.GeneratedPluginRegistrant { *; } | ||
# Google Play Core (for Flutter engine) | ||
-keep class com.google.android.play.core.** { *; } | ||
-dontwarn com.google.android.play.core.** | ||
Comment on lines
+64
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we put all these in example-app proguard-rules? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is added into example app proguard rules. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once added into example proguard, we can remove these from here to simplify? |
||
# Additional safety for Optimizely | ||
-keep class com.optimizely.** { *; } | ||
-dontwarn com.optimizely.** | ||
muzahidul-opti marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
# Jackson JSON | ||
-keep class com.fasterxml.jackson.** { *; } | ||
-dontwarn com.fasterxml.jackson.** | ||
# Ignore missing classes | ||
-dontwarn javax.mail.** | ||
-dontwarn javax.activation.** | ||
EOF | ||
- name: Test with minification ENABLED | ||
run: | | ||
echo "🧪 Testing with minifyEnabled = true" | ||
# Backup original build.gradle | ||
cp example/android/app/build.gradle example/android/app/build.gradle.backup | ||
# Enable minification | ||
sed -i 's/minifyEnabled false/minifyEnabled true/' example/android/app/build.gradle | ||
sed -i 's/shrinkResources false/shrinkResources true/' example/android/app/build.gradle | ||
# Ensure ProGuard rules are applied | ||
if ! grep -q "proguardFiles.*proguard-rules.pro" example/android/app/build.gradle; then | ||
sed -i '/minifyEnabled true/a\ proguardFiles getDefaultProguardFile('\''proguard-android-optimize.txt'\''), '\''proguard-rules.pro'\''' example/android/app/build.gradle | ||
fi | ||
echo "📄 Build configuration with minification:" | ||
grep -A 5 "buildTypes" example/android/app/build.gradle | ||
# Build for single architecture to save memory | ||
cd example | ||
flutter build apk --release --target-platform android-arm64 --split-per-abi | ||
echo "✅ Build successful with minification ENABLED" | ||
- name: Test with minification DISABLED | ||
run: | | ||
echo "🧪 Testing with minifyEnabled = false" | ||
# Restore original | ||
cp example/android/app/build.gradle.backup example/android/app/build.gradle | ||
sed -i 's/minifyEnabled true/minifyEnabled false/' example/android/app/build.gradle | ||
sed -i 's/shrinkResources true/shrinkResources false/' example/android/app/build.gradle | ||
echo "📄 Build configuration without minification:" | ||
grep -A 5 "buildTypes" example/android/app/build.gradle | ||
# Clean and build | ||
cd example | ||
flutter clean | ||
flutter build apk --release --target-platform android-arm64 --split-per-abi | ||
echo "✅ Build successful with minification DISABLED" | ||
- name: Run unit tests | ||
run: flutter test | ||
|
||
- name: Verify APK artifacts | ||
run: | | ||
echo "📱 Checking APK files:" | ||
find example/build/app/outputs/apk/ -name "*.apk" -exec ls -la {} \; | ||
- name: Check for ProGuard artifacts | ||
run: | | ||
echo "🔍 Checking for ProGuard/R8 artifacts:" | ||
if [ -f "example/build/app/outputs/mapping/release/mapping.txt" ]; then | ||
echo "✅ ProGuard mapping file found" | ||
echo "📄 Mapping file size: $(wc -l < example/build/app/outputs/mapping/release/mapping.txt) lines" | ||
else | ||
echo "ℹ️ No mapping file found" | ||
fi | ||
- name: Upload APK artifacts | ||
|
||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: minification-test-apk | ||
path: | | ||
example/build/app/outputs/apk/release/*.apk | ||
example/build/app/outputs/mapping/release/mapping.txt | ||
retention-days: 7 | ||
|
||
- name: Report test results | ||
run: | | ||
echo "🎉 Minification compatibility test completed!" | ||
echo "✅ minifyEnabled = true: PASSED" | ||
echo "✅ minifyEnabled = false: PASSED" | ||
echo "✅ Memory optimizations applied successfully" | ||
- name: Cleanup | ||
if: always() | ||
run: | | ||
if [ -f "example/android/app/build.gradle.backup" ]; then | ||
mv example/android/app/build.gradle.backup example/android/app/build.gradle | ||
echo "✅ Restored original build.gradle" | ||
fi | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit - new line |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,8 +59,8 @@ android { | |
|
||
buildTypes { | ||
release { | ||
minifyEnabled true | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
minifyEnabled true | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt', 'proguard-rules.pro' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this change? I understand There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We added 'proguard-rules.txt' here to apply in the release build. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then we can drop "proguard-rules.pro" here? |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,28 @@ | |
# Add any project specific keep options here: | ||
|
||
# Optimizely | ||
-keep class com.optimizely.optimizely_flutter_sdk.** {*;} | ||
-keep class com.fasterxml.jackson.** {*;} | ||
# Logback | ||
-keep class ch.qos.** { *; } | ||
-keep class com.optimizely.optimizely_flutter_sdk.OptimizelyFlutterSdkPlugin { *; } | ||
-keep class com.optimizely.optimizely_flutter_sdk.** { *; } | ||
-keep class com.optimizely.ab.** { *; } | ||
|
||
# Keep Jackson classes for JSON parsing | ||
-keep class com.fasterxml.jackson.** { *; } | ||
-dontwarn com.fasterxml.jackson.** | ||
Comment on lines
+13
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why Jackson here? Do we use Jackson in our sdk plugin? |
||
|
||
# Keep Guava classes | ||
-keep class com.google.common.** { *; } | ||
-dontwarn com.google.common.** | ||
-dontwarn com.google.android.play.core.** | ||
|
||
# Keep SLF4J and Logback classes | ||
-keep class org.slf4j.** { *; } | ||
-keep class ch.qos.logback.** { *; } | ||
-dontwarn org.slf4j.** | ||
-dontwarn ch.qos.logback.** | ||
|
||
# Missing Dependencies (Android doesn't have these) | ||
-dontwarn javax.mail.** | ||
-dontwarn javax.activation.** | ||
-dontwarn javax.servlet.** | ||
|
||
|
||
##---------------End: proguard configuration ---------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit - a new line