diff --git a/.github/workflows/flutter.yml b/.github/workflows/flutter.yml index fe24b49..ffcce73 100644 --- a/.github/workflows/flutter.yml +++ b/.github/workflows/flutter.yml @@ -170,4 +170,4 @@ jobs: channel: 'stable' architecture: x64 - run: flutter pub get - - run: flutter test + - run: flutter test \ No newline at end of file diff --git a/.github/workflows/minification.yml b/.github/workflows/minification.yml new file mode 100644 index 0000000..bd3db11 --- /dev/null +++ b/.github/workflows/minification.yml @@ -0,0 +1,159 @@ +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.** + + # 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: 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 \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle index c33dcee..8559cd6 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -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' } } diff --git a/android/proguard-rules.txt b/android/proguard-rules.txt index 1564ced..b3914f4 100644 --- a/android/proguard-rules.txt +++ b/android/proguard-rules.txt @@ -8,8 +8,11 @@ # 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.** { *; } + +# Keep Jackson classes for JSON parsing +-keep class com.fasterxml.jackson.** { *; } +-dontwarn com.fasterxml.jackson.** + + ##---------------End: proguard configuration ---------- diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index bd22a12..21cea4c 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -59,5 +59,5 @@ flutter { } dependencies { - implementation 'com.android.support:multidex:1.0.3' + implementation 'com.android.support:multidex:2.0.0' }