From 9f084653eb9200e70b38e28eedd4e25fcfe535f2 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Thu, 10 Oct 2024 16:19:22 +0200 Subject: [PATCH 1/2] use custom app name for android when looking for build.gradle --- .../src/config/__fixtures__/android.ts | 17 +++++++++++++++++ .../config/__tests__/findBuildGradle.test.ts | 9 +++++++++ .../src/config/findBuildGradle.ts | 10 +++++++--- .../cli-platform-android/src/config/index.ts | 2 +- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/packages/cli-platform-android/src/config/__fixtures__/android.ts b/packages/cli-platform-android/src/config/__fixtures__/android.ts index f8ba3e141..7d96ac391 100644 --- a/packages/cli-platform-android/src/config/__fixtures__/android.ts +++ b/packages/cli-platform-android/src/config/__fixtures__/android.ts @@ -71,6 +71,20 @@ function generateValidFileStructureForApp() { }; } +function generateValidFileStructureForAppWithCustomAppName( + customAppName: string, +) { + return { + 'build.gradle': buildGradle, + [customAppName]: { + 'build.gradle': appBuildGradle, + }, + src: { + 'AndroidManifest.xml': manifest, + }, + }; +} + export const valid = generateValidFileStructureForLib('ReactPackage.java'); export const validKotlin = generateValidFileStructureForLib('ReactPackage.kt'); @@ -83,6 +97,9 @@ export const validKotlinWithDifferentFileName = export const validApp = generateValidFileStructureForApp(); +export const validAppWithCustomAppName = + generateValidFileStructureForAppWithCustomAppName('custom'); + export const userConfigManifest = { src: { main: { diff --git a/packages/cli-platform-android/src/config/__tests__/findBuildGradle.test.ts b/packages/cli-platform-android/src/config/__tests__/findBuildGradle.test.ts index c2a5c099e..770bb5513 100644 --- a/packages/cli-platform-android/src/config/__tests__/findBuildGradle.test.ts +++ b/packages/cli-platform-android/src/config/__tests__/findBuildGradle.test.ts @@ -21,6 +21,9 @@ describe('findBuildGradle for apps', () => { flat: { android: mocks.validApp, }, + customPath: { + android: mocks.validAppWithCustomAppName, + }, }); }); @@ -33,6 +36,12 @@ describe('findBuildGradle for apps', () => { it('returns `null` if there is no gradle in the app folder', () => { expect(findBuildGradle('/empty', false)).toBeNull(); }); + + it('returns the app build.gradle with custom app name', () => { + expect(findBuildGradle('/customPath/android', false, 'custom')).toBe( + '/customPath/android/custom/build.gradle', + ); + }); }); describe('findBuildGradle for libraries', () => { diff --git a/packages/cli-platform-android/src/config/findBuildGradle.ts b/packages/cli-platform-android/src/config/findBuildGradle.ts index d7320dcbd..fbea308de 100644 --- a/packages/cli-platform-android/src/config/findBuildGradle.ts +++ b/packages/cli-platform-android/src/config/findBuildGradle.ts @@ -1,14 +1,18 @@ import fs from 'fs'; import path from 'path'; -export function findBuildGradle(sourceDir: string, isLibrary: boolean) { +export function findBuildGradle( + sourceDir: string, + isLibrary: boolean, + appName = 'app', +) { const buildGradlePath = path.join( sourceDir, - isLibrary ? 'build.gradle' : 'app/build.gradle', + isLibrary ? 'build.gradle' : `${appName}/build.gradle`, ); const buildGradleKtsPath = path.join( sourceDir, - isLibrary ? 'build.gradle.kts' : 'app/build.gradle.kts', + isLibrary ? 'build.gradle.kts' : `${appName}/build.gradle.kts`, ); if (fs.existsSync(buildGradlePath)) { diff --git a/packages/cli-platform-android/src/config/index.ts b/packages/cli-platform-android/src/config/index.ts index 37e4f9345..54563d44d 100644 --- a/packages/cli-platform-android/src/config/index.ts +++ b/packages/cli-platform-android/src/config/index.ts @@ -48,7 +48,7 @@ export function projectConfig( const manifestPath = userConfig.manifestPath ? path.join(sourceDir, userConfig.manifestPath) : findManifest(path.join(sourceDir, appName)); - const buildGradlePath = findBuildGradle(sourceDir, false); + const buildGradlePath = findBuildGradle(sourceDir, false, appName); if (!manifestPath && !buildGradlePath) { return null; From 80e33ef0470813f0af5310104b6087b770029ad3 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Mon, 14 Oct 2024 08:25:35 +0200 Subject: [PATCH 2/2] fix tests --- packages/cli-platform-android/src/config/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/cli-platform-android/src/config/index.ts b/packages/cli-platform-android/src/config/index.ts index 54563d44d..3daf77c2d 100644 --- a/packages/cli-platform-android/src/config/index.ts +++ b/packages/cli-platform-android/src/config/index.ts @@ -48,7 +48,11 @@ export function projectConfig( const manifestPath = userConfig.manifestPath ? path.join(sourceDir, userConfig.manifestPath) : findManifest(path.join(sourceDir, appName)); - const buildGradlePath = findBuildGradle(sourceDir, false, appName); + const buildGradlePath = findBuildGradle( + sourceDir, + false, + appName === '' ? 'app' : appName, + ); if (!manifestPath && !buildGradlePath) { return null;