Skip to content
Closed
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
19 changes: 19 additions & 0 deletions local-cli/core/__fixtures__/android.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ exports.valid = {
},
};

exports.validMultipleManifests = {
src: {
main: {
'AndroidManifest.xml': manifest,
com: {
some: {
example: {
'Main.java': mainJavaClass,
'ReactPackage.java': fs.readFileSync(path.join(__dirname, './files/ReactPackage.java')),
},
},
},
},
debug: {
'AndroidManifest.xml': manifest
},
},
};

exports.corrupted = {
src: {
'AndroidManifest.xml': manifest,
Expand Down
7 changes: 7 additions & 0 deletions local-cli/core/__tests__/android/findManifest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ describe('android::findManifest', () => {
flat: {
android: mocks.valid,
},
multipleManifests: {
android: mocks.validMultipleManifests,
},
}));

it('should return a manifest path if file exists in the folder', () => {
Expand All @@ -21,5 +24,9 @@ describe('android::findManifest', () => {
expect(findManifest('empty')).toBe(null);
});

it('should return the main manifest before other manifests', () => {
expect(findManifest('multipleManifests')).toMatch(/[\/\\]src[\/\\]main/);
});

afterAll(mockFs.restore);
});
27 changes: 22 additions & 5 deletions local-cli/core/config/android/findManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,33 @@ const glob = require('glob');
const path = require('path');

/**
* Find an android application path in the folder
* Find an AndroidManifest.xml in the folder.
*
* @param {String} folder Name of the folder where to seek
* @return {String}
*/
module.exports = function findManifest(folder) {
const manifestPath = glob.sync(path.join('**', 'AndroidManifest.xml'), {
// Android projects may contain multiple manifest files that are merged
// during build. Usually we should use the manifest file of the main source
// set at src/main/AndroidManifest.xml. If for some reason that manifest
// isn't available (e.g. with a highly customised build setup) we should
// look for the first manifest we find.
const globOptions = {
cwd: folder,
ignore: ['node_modules/**', '**/build/**', 'Examples/**', 'examples/**'],
})[0];
ignore: ['**/build/**'],
};

return manifestPath ? path.join(folder, manifestPath) : null;
const mainPattern = path.join('**', 'main', 'AndroidManifest.xml');
const mainManifestPath = glob.sync(mainPattern, globOptions)[0];

if (mainManifestPath) {
return path.join(folder, mainManifestPath);
}

// Here it's possible that we might not find the manifest that contains what
// our caller is looking for but this should be better than returning null.
const anyPattern = path.join('**', 'AndroidManifest.xml');
const anyManifestPath = glob.sync(anyPattern, globOptions)[0];

return anyManifestPath ? path.join(folder, anyManifestPath) : null;
};