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..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); + const buildGradlePath = findBuildGradle( + sourceDir, + false, + appName === '' ? 'app' : appName, + ); if (!manifestPath && !buildGradlePath) { return null;