From 2ad9dbfc728e14d0cc105c48d9f4d42a6b66208f Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Tue, 22 Oct 2024 14:19:07 +0200 Subject: [PATCH] fix(android): avoid loading legacy autolinking script --- .github/workflows/build.yml | 7 +- test-app.gradle | 11 +- test/android/test-app-util.test.ts | 254 +++++++++++++---------------- 3 files changed, 122 insertions(+), 150 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e1d809aa2..510bf0cd2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,6 @@ on: # Nightly builds against react-native@nightly at 4:00, Monday through Friday - cron: 0 4 * * 1-5 env: - GRADLE_HANGS_ON_WINDOWS: 1 # https://github.com/microsoft/react-native-test-app/issues/2206 HOMEBREW_NO_INSTALL_CLEANUP: 1 VisualStudioVersion: "17.0" concurrency: @@ -89,7 +88,7 @@ jobs: - name: Validate Gradle wrapper uses: gradle/actions/wrapper-validation@v4 - name: Populate Gradle cache - if: ${{ runner.os != 'Windows' || env.GRADLE_HANGS_ON_WINDOWS != '1' }} + if: ${{ runner.os != 'Windows' }} uses: ./.github/actions/gradle with: arguments: clean @@ -257,7 +256,7 @@ jobs: name: "Android" strategy: matrix: - runner: [ubuntu-24.04] # TODO: Re-add Windows: https://github.com/microsoft/react-native-test-app/issues/2206 + runner: [ubuntu-24.04, windows-2022] runs-on: ${{ matrix.runner }} steps: - name: Checkout @@ -305,7 +304,7 @@ jobs: strategy: matrix: template: [all, android] - runner: [ubuntu-24.04] # TODO: Re-add Windows: https://github.com/microsoft/react-native-test-app/issues/2206 + runner: [ubuntu-24.04, windows-2022] runs-on: ${{ matrix.runner }} if: ${{ github.event_name != 'schedule' }} steps: diff --git a/test-app.gradle b/test-app.gradle index 6c57b056b..efb9123ba 100644 --- a/test-app.gradle +++ b/test-app.gradle @@ -12,10 +12,11 @@ apply(from: "${testAppDir}/android/media-types.gradle") checkEnvironment(rootDir, testAppDir) applyConfigPlugins(rootDir, testAppDir) -def reactNativeDir = file(findNodeModulesPath("react-native", rootDir)) -def cliAndroidDir = findNodeModulesPath("@react-native-community/cli-platform-android", reactNativeDir) - -apply(from: "${cliAndroidDir}/native_modules.gradle") +def importLegacyAutolinkingModule = { rootDir -> + def reactNativeDir = file(findNodeModulesPath("react-native", rootDir)) + def cliAndroidDir = findNodeModulesPath("@react-native-community/cli-platform-android", reactNativeDir) + apply(from: "${cliAndroidDir}/native_modules.gradle") +} ext.applyTestAppSettings = { DefaultSettings settings -> settings.include(":app") @@ -46,6 +47,7 @@ ext.applyTestAppSettings = { DefaultSettings settings -> settings.project(path).projectDir = file(info.projectDir) } } else { + importLegacyAutolinkingModule(rootDir) applyNativeModulesSettingsGradle(settings) } @@ -65,6 +67,7 @@ ext.applyTestAppSettings = { DefaultSettings settings -> ext.applyTestAppModule = { Project project -> def reactNativeVersion = getPackageVersionNumber("react-native", rootDir) if (reactNativeVersion >= 0 && reactNativeVersion < v(0, 75, 0)) { + importLegacyAutolinkingModule(rootDir) applyNativeModulesAppBuildGradle(project) } diff --git a/test/android/test-app-util.test.ts b/test/android/test-app-util.test.ts index 35c97c469..8777dad6f 100644 --- a/test/android/test-app-util.test.ts +++ b/test/android/test-app-util.test.ts @@ -8,10 +8,6 @@ import { runGradleWithProject, } from "./gradle.js"; -// TODO: https://github.com/microsoft/react-native-test-app/issues/2206 -const GRADLE_HANGS_ON_WINDOWS = process.platform === "win32"; -const testOptions = { skip: GRADLE_HANGS_ON_WINDOWS }; - describe("test-app-util.gradle", () => { const defaultTestProject = "TestAppUtilTest"; @@ -25,12 +21,10 @@ describe("test-app-util.gradle", () => { } after(() => { - if (!testOptions.skip) { - removeProject(defaultTestProject); - } + removeProject(defaultTestProject); }); - it("getAppName() returns `displayName`", testOptions, async () => { + it("getAppName() returns `displayName`", async () => { const { status, stdout } = await runGradle({ "app.json": JSON.stringify({ name: "AppName", @@ -46,7 +40,7 @@ describe("test-app-util.gradle", () => { match(stdout, /getAppName\(\) = AppDisplayName/); }); - it("getApplicationId() returns default id", testOptions, async () => { + it("getApplicationId() returns default id", async () => { const { status, stdout } = await runGradle({ "app.json": JSON.stringify({ name: "AppName", @@ -62,7 +56,7 @@ describe("test-app-util.gradle", () => { match(stdout, /getApplicationId\(\) = com.microsoft.reacttestapp/); }); - it("getApplicationId() returns package name", testOptions, async () => { + it("getApplicationId() returns package name", async () => { const { status, stdout } = await runGradle({ "app.json": JSON.stringify({ name: "AppName", @@ -81,140 +75,116 @@ describe("test-app-util.gradle", () => { match(stdout, /getApplicationId\(\) = com.contoso.application.id/); }); - it( - "getPackageVersionNumber() returns `react-native` version as a number", - testOptions, - async () => { - const { status, stdout } = await runGradle({ - "android/build.gradle": buildGradle( - 'println("getPackageVersionNumber() = " + project.ext.getPackageVersionNumber("react-native", rootDir))' - ), - }); - - const versionNumber = toVersionNumber(reactNativeVersion()); - - equal(status, 0); - match( - stdout, - new RegExp(`getPackageVersionNumber\\(\\) = ${versionNumber}`) - ); - } - ); - - it( - "getSigningConfigs() fails if `storeFile` is missing", - testOptions, - async () => { - const { status, stderr } = await runGradle({ - "app.json": JSON.stringify({ - name: "AppName", - displayName: "AppDisplayName", - resources: ["dist/res", "dist/main.android.jsbundle"], - android: { signingConfigs: { debug: {} } }, - }), - "android/build.gradle": buildGradle( - 'println("getSigningConfigs() = " + project.ext.getSigningConfigs())' - ), - }); - - equal(status, 1); - match(stderr, /storeFile .* is missing/); - } - ); - - it( - "getSigningConfigs() skips empty `signingConfigs` config", - testOptions, - async () => { - const { status, stdout } = await runGradle({ - "app.json": JSON.stringify({ - name: "AppName", - displayName: "AppDisplayName", - resources: ["dist/res", "dist/main.android.jsbundle"], - android: { signingConfigs: {} }, - }), - "android/build.gradle": buildGradle( - 'println("getSigningConfigs() = " + project.ext.getSigningConfigs())' - ), - }); - - equal(status, 0); - match(stdout, /getSigningConfigs\(\) = \[:\]/); - } - ); - - it( - "getSigningConfigs() returns debug signing config", - testOptions, - async () => { - const { status, stdout } = await runGradle({ - "app.json": JSON.stringify({ - name: "AppName", - displayName: "AppDisplayName", - resources: ["dist/res", "dist/main.android.jsbundle"], - android: { - signingConfigs: { - debug: { - storeFile: "../README.md", - }, + it("getPackageVersionNumber() returns `react-native` version as a number", async () => { + const { status, stdout } = await runGradle({ + "android/build.gradle": buildGradle( + 'println("getPackageVersionNumber() = " + project.ext.getPackageVersionNumber("react-native", rootDir))' + ), + }); + + const versionNumber = toVersionNumber(reactNativeVersion()); + + equal(status, 0); + match( + stdout, + new RegExp(`getPackageVersionNumber\\(\\) = ${versionNumber}`) + ); + }); + + it("getSigningConfigs() fails if `storeFile` is missing", async () => { + const { status, stderr } = await runGradle({ + "app.json": JSON.stringify({ + name: "AppName", + displayName: "AppDisplayName", + resources: ["dist/res", "dist/main.android.jsbundle"], + android: { signingConfigs: { debug: {} } }, + }), + "android/build.gradle": buildGradle( + 'println("getSigningConfigs() = " + project.ext.getSigningConfigs())' + ), + }); + + equal(status, 1); + match(stderr, /storeFile .* is missing/); + }); + + it("getSigningConfigs() skips empty `signingConfigs` config", async () => { + const { status, stdout } = await runGradle({ + "app.json": JSON.stringify({ + name: "AppName", + displayName: "AppDisplayName", + resources: ["dist/res", "dist/main.android.jsbundle"], + android: { signingConfigs: {} }, + }), + "android/build.gradle": buildGradle( + 'println("getSigningConfigs() = " + project.ext.getSigningConfigs())' + ), + }); + + equal(status, 0); + match(stdout, /getSigningConfigs\(\) = \[:\]/); + }); + + it("getSigningConfigs() returns debug signing config", async () => { + const { status, stdout } = await runGradle({ + "app.json": JSON.stringify({ + name: "AppName", + displayName: "AppDisplayName", + resources: ["dist/res", "dist/main.android.jsbundle"], + android: { + signingConfigs: { + debug: { + storeFile: "../README.md", }, }, - }), - "android/build.gradle": buildGradle( - 'println("getSigningConfigs() = " + project.ext.getSigningConfigs())' - ), - }); - - equal(status, 0); - match( - stdout, - /getSigningConfigs\(\) = \[debug:\[keyAlias:androiddebugkey, keyPassword:android, storePassword:android, storeFile:.*\]\]/ - ); - } - ); - - it( - "getSigningConfigs() returns release signing config", - testOptions, - async () => { - const { status, stdout } = await runGradle({ - "app.json": JSON.stringify({ - name: "AppName", - displayName: "AppDisplayName", - resources: ["dist/res", "dist/main.android.jsbundle"], - android: { - signingConfigs: { - release: { - storeFile: "../README.md", - }, + }, + }), + "android/build.gradle": buildGradle( + 'println("getSigningConfigs() = " + project.ext.getSigningConfigs())' + ), + }); + + equal(status, 0); + match( + stdout, + /getSigningConfigs\(\) = \[debug:\[keyAlias:androiddebugkey, keyPassword:android, storePassword:android, storeFile:.*\]\]/ + ); + }); + + it("getSigningConfigs() returns release signing config", async () => { + const { status, stdout } = await runGradle({ + "app.json": JSON.stringify({ + name: "AppName", + displayName: "AppDisplayName", + resources: ["dist/res", "dist/main.android.jsbundle"], + android: { + signingConfigs: { + release: { + storeFile: "../README.md", }, }, - }), - "android/build.gradle": buildGradle( - 'println("getSigningConfigs() = " + project.ext.getSigningConfigs())' - ), - }); - - equal(status, 0); - match( - stdout, - /getSigningConfigs\(\) = \[release:\[keyAlias:androiddebugkey, keyPassword:android, storePassword:android, storeFile:.*\]\]/ - ); - } - ); - - it( - "toVersionNumber() handles pre-release identifiers", - testOptions, - async () => { - const { status, stdout } = await runGradle({ - "android/build.gradle": buildGradle( - 'println("toVersionNumber() = " + project.ext.toVersionNumber("1.2.3-053c2b4be"))' - ), - }); - - equal(status, 0); - match(stdout, new RegExp(`toVersionNumber\\(\\) = ${v(1, 2, 3)}`)); - } - ); + }, + }), + "android/build.gradle": buildGradle( + 'println("getSigningConfigs() = " + project.ext.getSigningConfigs())' + ), + }); + + equal(status, 0); + match( + stdout, + /getSigningConfigs\(\) = \[release:\[keyAlias:androiddebugkey, keyPassword:android, storePassword:android, storeFile:.*\]\]/ + ); + }); + + it("toVersionNumber() handles pre-release identifiers", async () => { + const { status, stdout } = await runGradle({ + "android/build.gradle": buildGradle( + 'println("toVersionNumber() = " + project.ext.toVersionNumber("1.2.3-053c2b4be"))' + ), + }); + + equal(status, 0); + match(stdout, new RegExp(`toVersionNumber\\(\\) = ${v(1, 2, 3)}`)); + }); });