Move Android template app E2E builds to Docker (#58564)

Summary:
Move Android template app APK generation into a dedicated reusable workflow that runs in `reactnativecommunity/react-native-android:latest`.

The emulator workflow now downloads the prebuilt debug or release APK and runs Maestro directly on the Ubuntu host. Only the debug lane reconstructs the generated project as a Metro workspace. E2E retries reuse the original APK artifacts instead of rebuilding the app.

This keeps KVM-backed emulators on the host while removing Gradle and NDK provisioning from the emulator jobs. It also aligns the template app flow with the existing RNTester build/test artifact boundary.

## Changelog:

[INTERNAL] [FIXED] - Build Android template E2E APKs in the Android container.

Pull Request resolved: https://github.com/react/react-native/pull/58564

Test Plan:
- `yarn prettier --check .github/workflows/build-android-templateapp.yml .github/workflows/e2e-android-templateapp.yml .github/workflows/test-all.yml` — passed
- `git diff --check` — passed
- Parsed all three changed workflow files with the repository's `yaml` package — passed
- Container build and emulator E2E were not run locally because Docker is unavailable; the GitHub Actions PR run will exercise the complete workflow.

Reviewed By: cipolleschi

Differential Revision: D120393969

Pulled By: cortinico

fbshipit-source-id: fde7eadd4f87145ccf501df4de214a5101df4746
This commit is contained in:
Nicola Corti authored and meta-codesync[bot] committed 2026-09-18 07:19:21 -07:00
1 parent 54f9cdfd20
commit 15d3bcad5a
3 files changed
+98 -36

No files matched your search

@@ -0,0 +1,74 @@
name: Build Android Template App
permissions:
contents: read
on:
workflow_call:
jobs:
build:
runs-on: 4-core-ubuntu
container:
image: reactnativecommunity/react-native-android:latest
env:
LC_ALL: C.UTF8
TERM: 'dumb'
GRADLE_OPTS: '-Dorg.gradle.daemon=false'
REACT_NATIVE_DOWNLOADS_DIR: /opt/react-native-downloads
strategy:
fail-fast: false
matrix:
flavor: [debug, release]
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup git safe folders
run: git config --global --add safe.directory '*'
- name: Setup node.js
uses: ./.github/actions/setup-node
- name: Run yarn
uses: ./.github/actions/yarn-install
- name: Download Maven Local
uses: actions/download-artifact@v7
with:
name: maven-local
path: /tmp/react-native-tmp/maven-local
- name: Download React Native Package
uses: actions/download-artifact@v7
with:
name: react-native-package
path: /tmp/react-native-tmp
- name: Build template app
shell: bash
run: |
REACT_NATIVE_PKG=$(find /tmp/react-native-tmp -type f -name "*.tgz")
MAVEN_LOCAL=/tmp/react-native-tmp/maven-local
# Stable branches use their matching template branch. All other
# builds use the template's main branch.
BRANCH=${{ github.ref_name }}
if ! [[ $BRANCH == *-stable* ]]; then
BRANCH=main
fi
node ./scripts/e2e/init-project-e2e.js \
--projectName RNTestProject \
--currentBranch "$BRANCH" \
--directory /tmp/RNTestProject \
--pathToLocalReactNative "$REACT_NATIVE_PKG"
echo -e "\nreact.internal.mavenLocalRepo=$MAVEN_LOCAL" >> /tmp/RNTestProject/android/gradle.properties
CAPITALIZED_FLAVOR=$(echo "${{ matrix.flavor }}" | awk '{print toupper(substr($0, 1, 1)) substr($0, 2)}')
cd /tmp/RNTestProject/android
./gradlew --no-daemon \
--init-script "$GITHUB_WORKSPACE/.github/workflow-scripts/legacy-jni-packaging.gradle" \
assemble$CAPITALIZED_FLAVOR \
-PreactNativeArchitectures=arm64-v8a
- name: Upload template app APK
uses: actions/upload-artifact@v6
with:
name: android-templateapp-${{ matrix.flavor }}
path: /tmp/RNTestProject/android/app/build/outputs/apk/${{ matrix.flavor }}/app-${{ matrix.flavor }}.apk
compression-level: 0
if-no-files-found: error
+17 -35
View File
@@ -33,31 +33,18 @@ jobs:
uses: ./.github/actions/setup-node
- name: Run yarn
uses: ./.github/actions/yarn-install
- name: Set up JDK 17
uses: actions/setup-java@v5
with:
java-version: '17'
distribution: 'zulu'
- name: Download Maven Local
uses: actions/download-artifact@v7
with:
name: maven-local
path: /tmp/react-native-tmp/maven-local
# Debug APKs load JavaScript from Metro, so only that lane needs a
# generated project workspace.
- name: Download React Native Package
if: matrix.flavor == 'debug'
uses: actions/download-artifact@v7
with:
name: react-native-package
path: /tmp/react-native-tmp
- name: Print /tmp folder
run: ls -lR /tmp/react-native-tmp
- name: Prepare artifacts
id: prepare-artifacts
- name: Prepare Metro workspace
if: matrix.flavor == 'debug'
run: |
REACT_NATIVE_PKG=$(find /tmp/react-native-tmp -type f -name "*.tgz")
echo "React Native tgs is $REACT_NATIVE_PKG"
MAVEN_LOCAL=/tmp/react-native-tmp/maven-local
echo "Maven local path is $MAVEN_LOCAL"
# For stable branches, we want to use the stable branch of the template
# In all the other cases, we want to use "main"
@@ -65,20 +52,16 @@ jobs:
if ! [[ $BRANCH == *-stable* ]]; then
BRANCH=main
fi
node ./scripts/e2e/init-project-e2e.js --projectName RNTestProject --currentBranch $BRANCH --directory /tmp/RNTestProject --pathToLocalReactNative $REACT_NATIVE_PKG
echo "Feed maven local to gradle.properties"
cd /tmp/RNTestProject
echo -e "\nreact.internal.mavenLocalRepo=$MAVEN_LOCAL" >> android/gradle.properties
# Build
cd android
CAPITALIZED_FLAVOR=$(echo "${{ matrix.flavor }}" | awk '{print toupper(substr($0, 1, 1)) substr($0, 2)}')
./gradlew --no-daemon \
--init-script "$GITHUB_WORKSPACE/.github/workflow-scripts/legacy-jni-packaging.gradle" \
assemble$CAPITALIZED_FLAVOR \
-PreactNativeArchitectures=arm64-v8a
node ./scripts/e2e/init-project-e2e.js \
--projectName RNTestProject \
--currentBranch "$BRANCH" \
--directory /tmp/RNTestProject \
--pathToLocalReactNative "$REACT_NATIVE_PKG"
- name: Download template app APK
uses: actions/download-artifact@v7
with:
name: android-templateapp-${{ matrix.flavor }}
path: /tmp/android-templateapp
- name: Download previous per-flow test state
if: ${{ inputs.retry-attempt > 0 }}
continue-on-error: true
@@ -103,12 +86,11 @@ jobs:
uses: ./.github/actions/maestro-android
timeout-minutes: 90
with:
app-path: /tmp/RNTestProject/android/app/build/outputs/apk/${{ matrix.flavor }}/app-${{ matrix.flavor }}.apk
app-path: /tmp/android-templateapp/app-${{ matrix.flavor }}.apk
app-id: com.rntestproject
maestro-flow: ./scripts/e2e/.maestro/
install-java: 'false'
flavor: ${{ matrix.flavor }}
working-directory: /tmp/RNTestProject
working-directory: ${{ matrix.flavor == 'debug' && '/tmp/RNTestProject' || '.' }}
emulator-api-level: '35'
emulator-target: google_apis
emulator-arch: x86_64
+7 -1
View File
@@ -263,9 +263,15 @@ jobs:
uses: ./.github/workflows/test-ios-spm-newapp.yml
secrets: inherit
test_e2e_android_templateapp:
build_android_templateapp:
needs: [build_npm_package, build_android]
if: ${{ always() && needs.build_android.result == 'success' && needs.build_npm_package.result == 'success' }}
uses: ./.github/workflows/build-android-templateapp.yml
secrets: inherit
test_e2e_android_templateapp:
needs: build_android_templateapp
if: ${{ needs.build_android_templateapp.result == 'success' }}
uses: ./.github/workflows/e2e-android-templateapp.yml
secrets: inherit