Skip to content

Commit afa75aa

Browse files
authored
fix(android): avoid loading legacy autolinking script (#2291)
1 parent 07de81d commit afa75aa

File tree

3 files changed

+120
-148
lines changed

3 files changed

+120
-148
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ on:
99
# Nightly builds against react-native@nightly at 4:00, Monday through Friday
1010
- cron: 0 4 * * 1-5
1111
env:
12-
GRADLE_HANGS_ON_WINDOWS: 1 # https://github.com/microsoft/react-native-test-app/issues/2206
1312
HOMEBREW_NO_INSTALL_CLEANUP: 1
1413
VisualStudioVersion: "17.0"
1514
concurrency:
@@ -89,7 +88,6 @@ jobs:
8988
- name: Validate Gradle wrapper
9089
uses: gradle/actions/wrapper-validation@v4
9190
- name: Populate Gradle cache
92-
if: ${{ runner.os != 'Windows' || env.GRADLE_HANGS_ON_WINDOWS != '1' }}
9391
uses: ./.github/actions/gradle
9492
with:
9593
arguments: clean
@@ -257,7 +255,7 @@ jobs:
257255
name: "Android"
258256
strategy:
259257
matrix:
260-
runner: [ubuntu-24.04] # TODO: Re-add Windows: https://github.com/microsoft/react-native-test-app/issues/2206
258+
runner: [ubuntu-24.04, windows-2022]
261259
runs-on: ${{ matrix.runner }}
262260
steps:
263261
- name: Checkout
@@ -305,7 +303,7 @@ jobs:
305303
strategy:
306304
matrix:
307305
template: [all, android]
308-
runner: [ubuntu-24.04] # TODO: Re-add Windows: https://github.com/microsoft/react-native-test-app/issues/2206
306+
runner: [ubuntu-24.04, windows-2022]
309307
runs-on: ${{ matrix.runner }}
310308
if: ${{ github.event_name != 'schedule' }}
311309
steps:

test-app.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ checkEnvironment(rootDir, testAppDir)
1313
applyConfigPlugins(rootDir, testAppDir)
1414

1515
def reactNativeDir = file(findNodeModulesPath("react-native", rootDir))
16-
def cliAndroidDir = findNodeModulesPath("@react-native-community/cli-platform-android", reactNativeDir)
1716

18-
apply(from: "${cliAndroidDir}/native_modules.gradle")
17+
def importLegacyAutolinkingModule = { File startDir ->
18+
def cliAndroidDir = findNodeModulesPath("@react-native-community/cli-platform-android", startDir)
19+
apply(from: "${cliAndroidDir}/native_modules.gradle")
20+
}
1921

2022
ext.applyTestAppSettings = { DefaultSettings settings ->
2123
settings.include(":app")
@@ -46,6 +48,7 @@ ext.applyTestAppSettings = { DefaultSettings settings ->
4648
settings.project(path).projectDir = file(info.projectDir)
4749
}
4850
} else {
51+
importLegacyAutolinkingModule(reactNativeDir)
4952
applyNativeModulesSettingsGradle(settings)
5053
}
5154

@@ -65,6 +68,7 @@ ext.applyTestAppSettings = { DefaultSettings settings ->
6568
ext.applyTestAppModule = { Project project ->
6669
def reactNativeVersion = getPackageVersionNumber("react-native", rootDir)
6770
if (reactNativeVersion >= 0 && reactNativeVersion < v(0, 75, 0)) {
71+
importLegacyAutolinkingModule(reactNativeDir)
6872
applyNativeModulesAppBuildGradle(project)
6973
}
7074

test/android/test-app-util.test.ts

Lines changed: 112 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import {
88
runGradleWithProject,
99
} from "./gradle.js";
1010

11-
// TODO: https://github.com/microsoft/react-native-test-app/issues/2206
12-
const GRADLE_HANGS_ON_WINDOWS = process.platform === "win32";
13-
const testOptions = { skip: GRADLE_HANGS_ON_WINDOWS };
14-
1511
describe("test-app-util.gradle", () => {
1612
const defaultTestProject = "TestAppUtilTest";
1713

@@ -25,12 +21,10 @@ describe("test-app-util.gradle", () => {
2521
}
2622

2723
after(() => {
28-
if (!testOptions.skip) {
29-
removeProject(defaultTestProject);
30-
}
24+
removeProject(defaultTestProject);
3125
});
3226

33-
it("getAppName() returns `displayName`", testOptions, async () => {
27+
it("getAppName() returns `displayName`", async () => {
3428
const { status, stdout } = await runGradle({
3529
"app.json": JSON.stringify({
3630
name: "AppName",
@@ -46,7 +40,7 @@ describe("test-app-util.gradle", () => {
4640
match(stdout, /getAppName\(\) = AppDisplayName/);
4741
});
4842

49-
it("getApplicationId() returns default id", testOptions, async () => {
43+
it("getApplicationId() returns default id", async () => {
5044
const { status, stdout } = await runGradle({
5145
"app.json": JSON.stringify({
5246
name: "AppName",
@@ -62,7 +56,7 @@ describe("test-app-util.gradle", () => {
6256
match(stdout, /getApplicationId\(\) = com.microsoft.reacttestapp/);
6357
});
6458

65-
it("getApplicationId() returns package name", testOptions, async () => {
59+
it("getApplicationId() returns package name", async () => {
6660
const { status, stdout } = await runGradle({
6761
"app.json": JSON.stringify({
6862
name: "AppName",
@@ -81,140 +75,116 @@ describe("test-app-util.gradle", () => {
8175
match(stdout, /getApplicationId\(\) = com.contoso.application.id/);
8276
});
8377

84-
it(
85-
"getPackageVersionNumber() returns `react-native` version as a number",
86-
testOptions,
87-
async () => {
88-
const { status, stdout } = await runGradle({
89-
"android/build.gradle": buildGradle(
90-
'println("getPackageVersionNumber() = " + project.ext.getPackageVersionNumber("react-native", rootDir))'
91-
),
92-
});
93-
94-
const versionNumber = toVersionNumber(reactNativeVersion());
95-
96-
equal(status, 0);
97-
match(
98-
stdout,
99-
new RegExp(`getPackageVersionNumber\\(\\) = ${versionNumber}`)
100-
);
101-
}
102-
);
103-
104-
it(
105-
"getSigningConfigs() fails if `storeFile` is missing",
106-
testOptions,
107-
async () => {
108-
const { status, stderr } = await runGradle({
109-
"app.json": JSON.stringify({
110-
name: "AppName",
111-
displayName: "AppDisplayName",
112-
resources: ["dist/res", "dist/main.android.jsbundle"],
113-
android: { signingConfigs: { debug: {} } },
114-
}),
115-
"android/build.gradle": buildGradle(
116-
'println("getSigningConfigs() = " + project.ext.getSigningConfigs())'
117-
),
118-
});
119-
120-
equal(status, 1);
121-
match(stderr, /storeFile .* is missing/);
122-
}
123-
);
124-
125-
it(
126-
"getSigningConfigs() skips empty `signingConfigs` config",
127-
testOptions,
128-
async () => {
129-
const { status, stdout } = await runGradle({
130-
"app.json": JSON.stringify({
131-
name: "AppName",
132-
displayName: "AppDisplayName",
133-
resources: ["dist/res", "dist/main.android.jsbundle"],
134-
android: { signingConfigs: {} },
135-
}),
136-
"android/build.gradle": buildGradle(
137-
'println("getSigningConfigs() = " + project.ext.getSigningConfigs())'
138-
),
139-
});
140-
141-
equal(status, 0);
142-
match(stdout, /getSigningConfigs\(\) = \[:\]/);
143-
}
144-
);
145-
146-
it(
147-
"getSigningConfigs() returns debug signing config",
148-
testOptions,
149-
async () => {
150-
const { status, stdout } = await runGradle({
151-
"app.json": JSON.stringify({
152-
name: "AppName",
153-
displayName: "AppDisplayName",
154-
resources: ["dist/res", "dist/main.android.jsbundle"],
155-
android: {
156-
signingConfigs: {
157-
debug: {
158-
storeFile: "../README.md",
159-
},
78+
it("getPackageVersionNumber() returns `react-native` version as a number", async () => {
79+
const { status, stdout } = await runGradle({
80+
"android/build.gradle": buildGradle(
81+
'println("getPackageVersionNumber() = " + project.ext.getPackageVersionNumber("react-native", rootDir))'
82+
),
83+
});
84+
85+
const versionNumber = toVersionNumber(reactNativeVersion());
86+
87+
equal(status, 0);
88+
match(
89+
stdout,
90+
new RegExp(`getPackageVersionNumber\\(\\) = ${versionNumber}`)
91+
);
92+
});
93+
94+
it("getSigningConfigs() fails if `storeFile` is missing", async () => {
95+
const { status, stderr } = await runGradle({
96+
"app.json": JSON.stringify({
97+
name: "AppName",
98+
displayName: "AppDisplayName",
99+
resources: ["dist/res", "dist/main.android.jsbundle"],
100+
android: { signingConfigs: { debug: {} } },
101+
}),
102+
"android/build.gradle": buildGradle(
103+
'println("getSigningConfigs() = " + project.ext.getSigningConfigs())'
104+
),
105+
});
106+
107+
equal(status, 1);
108+
match(stderr, /storeFile .* is missing/);
109+
});
110+
111+
it("getSigningConfigs() skips empty `signingConfigs` config", async () => {
112+
const { status, stdout } = await runGradle({
113+
"app.json": JSON.stringify({
114+
name: "AppName",
115+
displayName: "AppDisplayName",
116+
resources: ["dist/res", "dist/main.android.jsbundle"],
117+
android: { signingConfigs: {} },
118+
}),
119+
"android/build.gradle": buildGradle(
120+
'println("getSigningConfigs() = " + project.ext.getSigningConfigs())'
121+
),
122+
});
123+
124+
equal(status, 0);
125+
match(stdout, /getSigningConfigs\(\) = \[:\]/);
126+
});
127+
128+
it("getSigningConfigs() returns debug signing config", async () => {
129+
const { status, stdout } = await runGradle({
130+
"app.json": JSON.stringify({
131+
name: "AppName",
132+
displayName: "AppDisplayName",
133+
resources: ["dist/res", "dist/main.android.jsbundle"],
134+
android: {
135+
signingConfigs: {
136+
debug: {
137+
storeFile: "../README.md",
160138
},
161139
},
162-
}),
163-
"android/build.gradle": buildGradle(
164-
'println("getSigningConfigs() = " + project.ext.getSigningConfigs())'
165-
),
166-
});
167-
168-
equal(status, 0);
169-
match(
170-
stdout,
171-
/getSigningConfigs\(\) = \[debug:\[keyAlias:androiddebugkey, keyPassword:android, storePassword:android, storeFile:.*\]\]/
172-
);
173-
}
174-
);
175-
176-
it(
177-
"getSigningConfigs() returns release signing config",
178-
testOptions,
179-
async () => {
180-
const { status, stdout } = await runGradle({
181-
"app.json": JSON.stringify({
182-
name: "AppName",
183-
displayName: "AppDisplayName",
184-
resources: ["dist/res", "dist/main.android.jsbundle"],
185-
android: {
186-
signingConfigs: {
187-
release: {
188-
storeFile: "../README.md",
189-
},
140+
},
141+
}),
142+
"android/build.gradle": buildGradle(
143+
'println("getSigningConfigs() = " + project.ext.getSigningConfigs())'
144+
),
145+
});
146+
147+
equal(status, 0);
148+
match(
149+
stdout,
150+
/getSigningConfigs\(\) = \[debug:\[keyAlias:androiddebugkey, keyPassword:android, storePassword:android, storeFile:.*\]\]/
151+
);
152+
});
153+
154+
it("getSigningConfigs() returns release signing config", async () => {
155+
const { status, stdout } = await runGradle({
156+
"app.json": JSON.stringify({
157+
name: "AppName",
158+
displayName: "AppDisplayName",
159+
resources: ["dist/res", "dist/main.android.jsbundle"],
160+
android: {
161+
signingConfigs: {
162+
release: {
163+
storeFile: "../README.md",
190164
},
191165
},
192-
}),
193-
"android/build.gradle": buildGradle(
194-
'println("getSigningConfigs() = " + project.ext.getSigningConfigs())'
195-
),
196-
});
197-
198-
equal(status, 0);
199-
match(
200-
stdout,
201-
/getSigningConfigs\(\) = \[release:\[keyAlias:androiddebugkey, keyPassword:android, storePassword:android, storeFile:.*\]\]/
202-
);
203-
}
204-
);
205-
206-
it(
207-
"toVersionNumber() handles pre-release identifiers",
208-
testOptions,
209-
async () => {
210-
const { status, stdout } = await runGradle({
211-
"android/build.gradle": buildGradle(
212-
'println("toVersionNumber() = " + project.ext.toVersionNumber("1.2.3-053c2b4be"))'
213-
),
214-
});
215-
216-
equal(status, 0);
217-
match(stdout, new RegExp(`toVersionNumber\\(\\) = ${v(1, 2, 3)}`));
218-
}
219-
);
166+
},
167+
}),
168+
"android/build.gradle": buildGradle(
169+
'println("getSigningConfigs() = " + project.ext.getSigningConfigs())'
170+
),
171+
});
172+
173+
equal(status, 0);
174+
match(
175+
stdout,
176+
/getSigningConfigs\(\) = \[release:\[keyAlias:androiddebugkey, keyPassword:android, storePassword:android, storeFile:.*\]\]/
177+
);
178+
});
179+
180+
it("toVersionNumber() handles pre-release identifiers", async () => {
181+
const { status, stdout } = await runGradle({
182+
"android/build.gradle": buildGradle(
183+
'println("toVersionNumber() = " + project.ext.toVersionNumber("1.2.3-053c2b4be"))'
184+
),
185+
});
186+
187+
equal(status, 0);
188+
match(stdout, new RegExp(`toVersionNumber\\(\\) = ${v(1, 2, 3)}`));
189+
});
220190
});

0 commit comments

Comments
 (0)