diff --git a/.github/actions/android/action.yml b/.github/actions/android/action.yml index 4ed487743..f8ad78fde 100644 --- a/.github/actions/android/action.yml +++ b/.github/actions/android/action.yml @@ -38,7 +38,7 @@ runs: cache: true flutter-version-file: pubspec.yaml - - name: Build Android APK/AAB + - name: Build preApi30 APK/AAB shell: bash env: STORE_PASS: ${{ inputs.STORE_PASS }} @@ -47,13 +47,29 @@ runs: VERSION_NAME: ${{inputs.VERSION_NAME}} VERSION_CODE: ${{inputs.VERSION_CODE}} run: | - flutter build apk --debug --build-name $VERSION_NAME --build-number $VERSION_CODE - flutter build apk --build-name $VERSION_NAME --build-number $VERSION_CODE - flutter build appbundle --build-name $VERSION_NAME --build-number $VERSION_CODE + flutter build apk --flavor preApi30 --debug --build-name $VERSION_NAME --build-number $VERSION_CODE + flutter build apk --flavor preApi30 --build-name $VERSION_NAME --build-number $VERSION_CODE + flutter build appbundle --flavor preApi30 --build-name $VERSION_NAME --build-number $VERSION_CODE - - name: Store APK file + - name: Build postApi30 APK/AAB + shell: bash + env: + STORE_PASS: ${{ inputs.STORE_PASS }} + ALIAS: ${{ inputs.ALIAS }} + KEY_PASS: ${{ inputs.KEY_PASS }} + VERSION_NAME: ${{inputs.VERSION_NAME}} + VERSION_CODE: ${{inputs.VERSION_CODE}} + run: | + flutter build apk --flavor postApi30 --debug --build-name $VERSION_NAME --build-number $VERSION_CODE + flutter build apk --flavor postApi30 --build-name $VERSION_NAME --build-number $VERSION_CODE + flutter build appbundle --flavor postApi30 --build-name $VERSION_NAME --build-number $VERSION_CODE + + - name: Store APK files uses: actions/upload-artifact@v4 with: name: apk-files path: | - build/app/outputs/flutter-apk/app-debug.apk \ No newline at end of file + build/app/outputs/flutter-apk/app-preapi30-debug.apk + build/app/outputs/flutter-apk/app-preapi30-release.apk + build/app/outputs/flutter-apk/app-postapi30-debug.apk + build/app/outputs/flutter-apk/app-postapi30-release.apk \ No newline at end of file diff --git a/.github/actions/screenshot-android/action.yml b/.github/actions/screenshot-android/action.yml index 491d0b694..ec94148c0 100644 --- a/.github/actions/screenshot-android/action.yml +++ b/.github/actions/screenshot-android/action.yml @@ -55,7 +55,14 @@ runs: cache: true flutter-version-file: pubspec.yaml - - name: Create Android Screenshots + - name: Create Android Screenshots (preApi30) + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: ${{ inputs.ANDROID_EMULATOR_API }} + arch: ${{ inputs.ANDROID_EMULATOR_ARCH }} + script: flutter drive --flavor preApi30 --driver=test_integration/test_driver.dart --target=test_integration/screenshots.dart -d emulator + + - name: Create Android Screenshots (postApi30) uses: reactivecircus/android-emulator-runner@v2 with: api-level: ${{ inputs.ANDROID_EMULATOR_API }} @@ -66,7 +73,7 @@ runs: emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none disable-animations: true script: | - DEVICE_NAME="Pixel 6" flutter drive --driver=test_integration/test_driver.dart --target=test_integration/screenshots.dart -d emulator + DEVICE_NAME="Pixel 6" flutter drive --flavor postApi30 --driver=test_integration/test_driver.dart --target=test_integration/screenshots.dart -d emulator - name: Update Fastlane Metadata if: ${{ github.event_name == 'push' }} diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index ae8d69ceb..41555d6e9 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -23,7 +23,26 @@ jobs: - name: Common Workflow uses: ./.github/actions/common - + + - name: Build preApi30 APK + run: flutter build apk --flavor preApi30 -t lib/main.dart + + - name: Build postApi30 APK + run: flutter build apk --flavor postApi30 -t lib/main.dart + + - name: Upload preApi30 APK + uses: actions/upload-artifact@v4 + with: + name: app-preapi30-release.apk + path: build/app/outputs/flutter-apk/app-preapi30-release.apk + + - name: Upload postApi30 APK + uses: actions/upload-artifact@v4 + with: + name: app-postapi30-release.apk + path: build/app/outputs/flutter-apk/app-postapi30-release.apk + + - name: Hydrate and Update Version id: flutter-version run: | diff --git a/README.md b/README.md index 35c040467..86518e769 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,31 @@ For this mode it is required that both the workstation and the device are on the Enable Wireless debugging as per the [documentation](https://developer.android.com/tools/adb#wireless-android11-command-line), then **pair** `adb pair :` and **connect** `adb connect :` and you should be able to find your device via `adb devices`. +## Building for Android (API Flavors) + +This project uses product flavors to support both pre-Android 11 and Android 11+ devices. **You must specify a flavor when building or running for Android!** + +- **For Android 10 and below:** + ```sh + flutter build apk --flavor preApi30 -t lib/main.dart + flutter run --flavor preApi30 -t lib/main.dart + ``` + Output: `build/app/outputs/flutter-apk/app-preapi30-release.apk` + +- **For Android 11 and above:** + ```sh + flutter build apk --flavor postApi30 -t lib/main.dart + flutter run --flavor postApi30 -t lib/main.dart + ``` + Output: `build/app/outputs/flutter-apk/app-postapi30-release.apk` + +If you do not specify a flavor, the build will fail due to missing `minSdkVersion` and `targetSdkVersion` in the default configuration. + +**Developer Note:** +- This is a standard practice for multi-target Android projects (such as those distributed on F-Droid). +- It ensures clarity and prevents accidental builds for the wrong Android version. +- If you want extra convenience, you can create local shell scripts or aliases, e.g., `run-pre.sh` with `flutter run --flavor preApi30 -t lib/main.dart` for faster development. +- Always check the README for up-to-date build instructions. ## LICENSE diff --git a/android/app/build.gradle b/android/app/build.gradle index 7fcaeb718..bdc8a4fe1 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -37,16 +37,25 @@ android { } defaultConfig { - // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "org.fossasia.badgemagic" - // You can update the following values to match your application needs. - // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. - minSdkVersion 21 - targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName } + flavorDimensions "api" + productFlavors { + preApi30 { + dimension "api" + minSdkVersion 21 + targetSdkVersion 29 + } + postApi30 { + dimension "api" + minSdkVersion 30 + targetSdkVersion 34 + } + } + signingConfigs { if (GITHUB_BUILD) { release {