Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ describe('findBuildGradle for apps', () => {
});

it('returns the app gradle path if file exists in the folder', () => {
expect(findBuildGradle('/flat/android', false)).toBe(
expect(findBuildGradle('/flat/android', 'app')).toBe(
'/flat/android/app/build.gradle',
);
});

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

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

it('returns the app gradle path if file exists in the folder', () => {
expect(findBuildGradle('/flat/android', true)).toBe(
expect(findBuildGradle('/flat/android', '')).toBe(
'/flat/android/build.gradle',
);
});

it('returns `null` if there is no gradle in the app folder', () => {
expect(findBuildGradle('/empty', true)).toBeNull();
expect(findBuildGradle('/empty', '')).toBeNull();
});
});
11 changes: 8 additions & 3 deletions packages/cli-config-android/src/config/findBuildGradle.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import fs from 'fs';
import path from 'path';

export function findBuildGradle(sourceDir: string, isLibrary: boolean) {
/**
* Find the build.gradle file for the given app name.
* This helper is used to find build.gradle file in both apps and libraries.
* For libraries, the appName is empty string.
*/
export function findBuildGradle(sourceDir: string, appName: string) {
const buildGradlePath = path.join(
sourceDir,
isLibrary ? 'build.gradle' : 'app/build.gradle',
path.join(appName, 'build.gradle'),
);
const buildGradleKtsPath = path.join(
sourceDir,
isLibrary ? 'build.gradle.kts' : 'app/build.gradle.kts',
path.join(appName, 'build.gradle.kts'),
);

if (fs.existsSync(buildGradlePath)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-config-android/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, appName);

if (!manifestPath && !buildGradlePath) {
return null;
Expand Down Expand Up @@ -125,7 +125,7 @@ export function dependencyConfig(
const manifestPath = userConfig.manifestPath
? path.join(sourceDir, userConfig.manifestPath)
: findManifest(sourceDir);
const buildGradlePath = findBuildGradle(sourceDir, true);
const buildGradlePath = findBuildGradle(sourceDir, '');
const isPureCxxDependency =
userConfig.cxxModuleCMakeListsModuleName != null &&
userConfig.cxxModuleCMakeListsPath != null &&
Expand Down
Loading