Skip to content

Commit

Permalink
fix(android): avoid loading legacy autolinking script
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 committed Oct 22, 2024
1 parent 76a2070 commit 2ad9dbf
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 150 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 7 additions & 4 deletions test-app.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -46,6 +47,7 @@ ext.applyTestAppSettings = { DefaultSettings settings ->
settings.project(path).projectDir = file(info.projectDir)
}
} else {
importLegacyAutolinkingModule(rootDir)
applyNativeModulesSettingsGradle(settings)
}

Expand All @@ -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)
}

Expand Down
254 changes: 112 additions & 142 deletions test/android/test-app-util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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)}`));
});
});

0 comments on commit 2ad9dbf

Please sign in to comment.