Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Update manifestWriter.js to fix #133 in Cordova 8. #135

Closed
wants to merge 6 commits into from
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
7 changes: 6 additions & 1 deletion hooks/lib/android/manifestWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Class injects plugin preferences into AndroidManifest.xml file.
*/

var path = require('path');
var fs = require('fs');
var xmlHelper = require('../xmlHelper.js');

module.exports = {
Expand All @@ -18,7 +19,11 @@ module.exports = {
* @param {Object} pluginPreferences - plugin preferences as JSON object; already parsed
*/
function writePreferences(cordovaContext, pluginPreferences) {
var pathToManifest = path.join(cordovaContext.opts.projectRoot, 'platforms', 'android', 'AndroidManifest.xml');
var pathToManifest = path.join(cordovaContext.opts.projectRoot, 'platforms', 'android', 'app', 'src', 'main', 'AndroidManifest.xml');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change it not backwards compatible and will break build with older Cordova android versions. Maybe you should check the cordova android version or copy the whole manifest file so it is compatible with older project structures.

if(!fs.existsSync(pathToManifest)){ // fallback for older cordova-android version, where the AndroidManifest resides in the root folder of the generated android project
pathToManifest = path.join(cordovaContext.opts.projectRoot, 'platforms', 'android', 'AndroidManifest.xml');
}

var manifestSource = xmlHelper.readXmlAsJson(pathToManifest);
var cleanManifest;
var updatedManifest;
Expand Down
12 changes: 10 additions & 2 deletions hooks/lib/ios/xcodePreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,16 @@ function loadProjectFile() {
projectFile = platform_ios.parseProjectFile(iosPlatformPath());
} catch (e) {
// let's try cordova 5.0 structure
platform_ios = context.requireCordovaModule('cordova-lib/src/plugman/platforms/ios');
projectFile = platform_ios.parseProjectFile(iosPlatformPath());
try {
platform_ios = context.requireCordovaModule('cordova-lib/src/plugman/platforms/ios');
projectFile = platform_ios.parseProjectFile(iosPlatformPath());
} catch(e) {
// try cordova 7.0 structure
var iosPlatformApi = require(path.join(iosPlatformPath(), '/cordova/Api'));
var projectFileApi = require(path.join(iosPlatformPath(), '/cordova/lib/projectFile.js'));
var locations = (new iosPlatformApi()).locations;
projectFile = projectFileApi.parse(locations);
}
}

return projectFile;
Expand Down