Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix react-native link issue when using multiple manifests #13373

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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.userConfigManifest = {
src: {
main: {
'AndroidManifest.xml': manifest,
com: {
some: {
example: {
'Main.java': mainJavaClass,
'ReactPackage.java': fs.readFileSync(path.join(__dirname, './files/ReactPackage.java')),
},
},
},
},
debug: {
'AndroidManifest.xml': fs.readFileSync(path.join(__dirname, './files/AndroidManifest-debug.xml')),
},
},
};

exports.corrupted = {
src: {
'AndroidManifest.xml': manifest,
Expand Down
3 changes: 3 additions & 0 deletions local-cli/core/__fixtures__/files/AndroidManifest-debug.xml
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>
13 changes: 13 additions & 0 deletions local-cli/core/__tests__/android/getProjectConfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ describe('android::getProjectConfig', () => {
flat: {
android: mocks.valid,
},
multiple: {
android: mocks.userConfigManifest,
},
noManifest: {
android: {},
},
Expand Down Expand Up @@ -43,6 +46,16 @@ describe('android::getProjectConfig', () => {
expect(getProjectConfig(folder, userConfig)).not.toBe(null);
expect(typeof getProjectConfig(folder, userConfig)).toBe('object');
});

it('multiple', () => {
const userConfig = {
manifestPath: 'src/main/AndroidManifest.xml'
};
const folder = 'multiple';

expect(getProjectConfig(folder, userConfig)).not.toBe(null);
expect(typeof getProjectConfig(folder, userConfig)).toBe('object');
});
});

it('should return `null` if android project was not found', () => {
Expand Down
13 changes: 11 additions & 2 deletions local-cli/core/android/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ exports.projectConfig = function projectConfigAndroid(folder, userConfig) {

const sourceDir = path.join(folder, src);
const isFlat = sourceDir.indexOf('app') === -1;
const manifestPath = findManifest(sourceDir);
const manifestPath = userConfig.manifestPath
? path.join(sourceDir, userConfig.manifestPath)
: findManifest(sourceDir);

if (!manifestPath) {
return null;
Expand All @@ -38,6 +40,11 @@ exports.projectConfig = function projectConfigAndroid(folder, userConfig) {
const manifest = readManifest(manifestPath);

const packageName = userConfig.packageName || getPackageName(manifest);

if (!packageName) {
throw new Error(`Package name not found in ${manifestPath}`);
}

const packageFolder = userConfig.packageFolder ||
packageName.replace(/\./g, path.sep);

Expand Down Expand Up @@ -92,7 +99,9 @@ exports.dependencyConfig = function dependencyConfigAndroid(folder, userConfig)
}

const sourceDir = path.join(folder, src);
const manifestPath = findManifest(sourceDir);
const manifestPath = userConfig.manifestPath
? path.join(sourceDir, userConfig.manifestPath)
: findManifest(sourceDir);

if (!manifestPath) {
return null;
Expand Down