Skip to content

Commit b780971

Browse files
committed
fix(android): hardcoded appName when finding build.gradle
1 parent 4ea2b35 commit b780971

3 files changed

Lines changed: 14 additions & 9 deletions

File tree

packages/cli-config-android/src/config/__tests__/findBuildGradle.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ describe('findBuildGradle for apps', () => {
2525
});
2626

2727
it('returns the app gradle path if file exists in the folder', () => {
28-
expect(findBuildGradle('/flat/android', false)).toBe(
28+
expect(findBuildGradle('/flat/android', 'app')).toBe(
2929
'/flat/android/app/build.gradle',
3030
);
3131
});
3232

3333
it('returns `null` if there is no gradle in the app folder', () => {
34-
expect(findBuildGradle('/empty', false)).toBeNull();
34+
expect(findBuildGradle('/empty', 'app')).toBeNull();
3535
});
3636
});
3737

@@ -46,12 +46,12 @@ describe('findBuildGradle for libraries', () => {
4646
});
4747

4848
it('returns the app gradle path if file exists in the folder', () => {
49-
expect(findBuildGradle('/flat/android', true)).toBe(
49+
expect(findBuildGradle('/flat/android', '')).toBe(
5050
'/flat/android/build.gradle',
5151
);
5252
});
5353

5454
it('returns `null` if there is no gradle in the app folder', () => {
55-
expect(findBuildGradle('/empty', true)).toBeNull();
55+
expect(findBuildGradle('/empty', '')).toBeNull();
5656
});
5757
});

packages/cli-config-android/src/config/findBuildGradle.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import fs from 'fs';
22
import path from 'path';
33

4-
export function findBuildGradle(sourceDir: string, isLibrary: boolean) {
4+
/**
5+
* Find the build.gradle file for the given app name.
6+
* This helper is used to find build.gradle file in both apps and libraries.
7+
* For libraries, the appName is empty string.
8+
*/
9+
export function findBuildGradle(sourceDir: string, appName: string) {
510
const buildGradlePath = path.join(
611
sourceDir,
7-
isLibrary ? 'build.gradle' : 'app/build.gradle',
12+
path.join(appName, 'build.gradle'),
813
);
914
const buildGradleKtsPath = path.join(
1015
sourceDir,
11-
isLibrary ? 'build.gradle.kts' : 'app/build.gradle.kts',
16+
path.join(appName, 'build.gradle.kts'),
1217
);
1318

1419
if (fs.existsSync(buildGradlePath)) {

packages/cli-config-android/src/config/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function projectConfig(
4848
const manifestPath = userConfig.manifestPath
4949
? path.join(sourceDir, userConfig.manifestPath)
5050
: findManifest(path.join(sourceDir, appName));
51-
const buildGradlePath = findBuildGradle(sourceDir, false);
51+
const buildGradlePath = findBuildGradle(sourceDir, appName);
5252

5353
if (!manifestPath && !buildGradlePath) {
5454
return null;
@@ -125,7 +125,7 @@ export function dependencyConfig(
125125
const manifestPath = userConfig.manifestPath
126126
? path.join(sourceDir, userConfig.manifestPath)
127127
: findManifest(sourceDir);
128-
const buildGradlePath = findBuildGradle(sourceDir, true);
128+
const buildGradlePath = findBuildGradle(sourceDir, '');
129129
const isPureCxxDependency =
130130
userConfig.cxxModuleCMakeListsModuleName != null &&
131131
userConfig.cxxModuleCMakeListsPath != null &&

0 commit comments

Comments
 (0)