Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -30,6 +30,14 @@ const classNameManifest = fs.readFileSync(
path.join(__dirname, './files/AndroidManifest-className.xml'),
);

const customFlavorManifest = fs.readFileSync(
path.join(__dirname, './files/AndroidManifest-custom-flavor.xml'),
);

const mainManifest = fs.readFileSync(
path.join(__dirname, './files/AndroidManifest.xml'),
);

function generateValidFileStructureForLib(classFileName: string) {
return {
'build.gradle': buildGradle,
Expand Down Expand Up @@ -298,3 +306,14 @@ export const className = {
'AndroidManifest.xml': classNameManifest,
},
};

export const customFlavor = {
src: {
e2e: {
'AndroidManifest.xml': customFlavorManifest,
},
main: {
'AndroidManifest.xml': mainManifest,
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest
xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ describe('android::getMainActivity', () => {
app: mocks.fewActivities,
},
},
customFlavor: {
android: {
app: mocks.customFlavor,
},
},
});
});

Expand Down Expand Up @@ -53,6 +58,14 @@ describe('android::getMainActivity', () => {
expect(mainActivity).toBe('com.example.ExampleAppActivity');
});

it('returns main activity from main manifest when custom flavors are defined', () => {
const manifestPath = findManifest('/customFlavor');
const mainActivity = getMainActivity(manifestPath || '');
expect(mainActivity).not.toBeNull();
expect(typeof mainActivity).toBe('string');
expect(mainActivity).toBe('.MainActivity');
});

it('returns null if file do not exist', () => {
const fakeManifestPath = findManifest('/empty');
expect(getMainActivity(fakeManifestPath || '')).toBeNull();
Expand Down
15 changes: 12 additions & 3 deletions packages/cli-platform-android/src/config/findManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import glob from 'glob';
import path from 'path';

export default function findManifest(folder: string) {
const manifestPath = glob.sync(path.join('**', 'AndroidManifest.xml'), {
let manifestPaths = glob.sync(path.join('**', 'AndroidManifest.xml'), {
cwd: folder,
ignore: [
'node_modules/**',
Expand All @@ -23,7 +23,16 @@ export default function findManifest(folder: string) {
'**/src/androidTest/**',
'**/src/test/**',
],
})[0];
});
if (manifestPaths.length > 1) {
// if we have more than one manifest, pick the one in the main folder if present
const mainManifest = manifestPaths.filter((manifestPath) =>
manifestPath.includes('src/main/'),
);
if (mainManifest.length === 1) {
manifestPaths = mainManifest;
}
}

return manifestPath ? path.join(folder, manifestPath) : null;
return manifestPaths[0] ? path.join(folder, manifestPaths[0]) : null;
}