diff --git a/.github/workflows/android.yaml b/.github/workflows/android.yaml index b881255f6094..3ce66c265e5c 100644 --- a/.github/workflows/android.yaml +++ b/.github/workflows/android.yaml @@ -143,3 +143,29 @@ jobs: path: | ~/.android/avd/* ~/.android/adb* + + agp9-compatibility: + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 + - uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b + with: + distribution: 'temurin' + java-version: '21' + - uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff + with: + channel: 'stable' + cache: true + cache-key: "flutter-:os:-:channel:-:version:-:arch:-:hash:" + pub-cache-key: "flutter-pub-:os:-:channel:-:version:-:arch:-:hash:" + - uses: bluefireteam/melos-action@705015c3d2bc4ab94201ac24accb2bbe070cf533 + with: + run-bootstrap: false + melos-version: '5.3.0' + - name: 'Bootstrap tests package' + run: melos bootstrap --scope tests + - name: Gradle cache + uses: gradle/actions/setup-gradle@v4 + - name: 'Build tests app with AGP 9' + run: bash ./.github/workflows/scripts/agp9-compatibility.sh diff --git a/.github/workflows/scripts/agp9-compatibility.sh b/.github/workflows/scripts/agp9-compatibility.sh new file mode 100644 index 000000000000..9cf19d2c40ea --- /dev/null +++ b/.github/workflows/scripts/agp9-compatibility.sh @@ -0,0 +1,44 @@ +#!/bin/bash +set -euo pipefail + +AGP_VERSION="${AGP_VERSION:-9.0.1}" +GRADLE_VERSION="${GRADLE_VERSION:-9.1.0}" + +TEST_ANDROID_DIR="tests/android" + +perl -0pi -e "s/id \"com\.android\.application\" version \"[^\"]+\" apply false/id \"com.android.application\" version \"$AGP_VERSION\" apply false/" \ + "$TEST_ANDROID_DIR/settings.gradle" + +perl -0pi -e "s#distributionUrl=https\\\\://services.gradle.org/distributions/gradle-[^-]+-all.zip#distributionUrl=https\\\\://services.gradle.org/distributions/gradle-$GRADLE_VERSION-all.zip#" \ + "$TEST_ANDROID_DIR/gradle/wrapper/gradle-wrapper.properties" + +# Flutter's Gradle plugin does not fully support AGP 9's new DSL yet. Opt out in +# this CI-only checkout so the job validates FlutterFire plugin compatibility. +# https://docs.flutter.cn/release/breaking-changes/migrate-to-agp-9/ +grep -q '^android.newDsl=false$' "$TEST_ANDROID_DIR/gradle.properties" || \ + printf '\nandroid.newDsl=false\n' >> "$TEST_ANDROID_DIR/gradle.properties" + +# AGP 9 has built-in Kotlin support. Keep the compatibility check focused on +# FlutterFire plugins by applying the same migration to the test app at runtime. +perl -0pi -e 's/\n\s*id "kotlin-android"\n/\n/' "$TEST_ANDROID_DIR/app/build.gradle" +perl -0pi -e 's/\n\s*kotlinOptions \{\n\s*jvmTarget = JavaVersion\.VERSION_17\n\s*\}\n/\n/' "$TEST_ANDROID_DIR/app/build.gradle" + +# AGP 9 rejects older Espresso artifacts that share the same namespace. +grep -q 'androidx.test.espresso:espresso-core:3.7.0' "$TEST_ANDROID_DIR/app/build.gradle" || cat <<'EOF' >> "$TEST_ANDROID_DIR/app/build.gradle" + +dependencies { + debugImplementation 'androidx.test.espresso:espresso-core:3.7.0' + debugImplementation 'androidx.test.espresso:espresso-idling-resource:3.7.0' +} +EOF + +grep -q "id \"com.android.application\" version \"$AGP_VERSION\" apply false" "$TEST_ANDROID_DIR/settings.gradle" +grep -q "gradle-$GRADLE_VERSION-all.zip" "$TEST_ANDROID_DIR/gradle/wrapper/gradle-wrapper.properties" +grep -q '^android.newDsl=false$' "$TEST_ANDROID_DIR/gradle.properties" +! grep -q 'id "kotlin-android"' "$TEST_ANDROID_DIR/app/build.gradle" +! grep -q 'kotlinOptions' "$TEST_ANDROID_DIR/app/build.gradle" +grep -q 'androidx.test.espresso:espresso-core:3.7.0' "$TEST_ANDROID_DIR/app/build.gradle" +grep -q 'androidx.test.espresso:espresso-idling-resource:3.7.0' "$TEST_ANDROID_DIR/app/build.gradle" + +cd tests +flutter build apk --debug --dart-define=CI=true --no-android-gradle-daemon