dpa99c / cordova-custom-config Goto Github PK
View Code? Open in Web Editor NEWCordova/Phonegap plugin to update platform configuration files based on preferences and config-file data defined in config.xml
Cordova/Phonegap plugin to update platform configuration files based on preferences and config-file data defined in config.xml
Is there a way to add localized keys/strings to ios plist
files with this plugin? Especially for the NSLocationWhenInUseUsageDescription
When the plugin is installed, Android version code and iOS bundle version are not updated in the platforms from their values in config.xml
Widget element looks like this:
<widget android-versionCode="28" id="com.app.my" ios-CFBundleVersion="28" version="3.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
With the plugin removed, values update correctly.
Adding android project...
Creating Cordova project for the Android platform:
Path: platforms\android
Package: co.centure.mobile
Name: CNATURE
Activity: MainActivity
Android target: android-22
Copying template files...
Android project created with [email protected]
Error: Cannot find module 'elementtree'
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object. (C:\Users\oak\git\centure\centure-app\beethoven\plugin s\cordova-custom-config\hooks\fileUtils.js:7:10)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
Please change the package.json so the plugin will install at least lodash 4.0.0.
I had to rollback to version 1.1.8 because I got cordova-custom-config: Error updating config for platform 'android': _.keyBy is not a function
, same for ios. The plugin installed lodash 3.10.1.
with this config:
<config-file parent="/*" target="AndroidManifest.xml">
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
</config-file>
generated file AndroidManifest.xml contains twice android.hardware.camera.autofocus
but not android.hardware.camera
Adding this plugin runs https://github.com/dpa99c/cordova-custom-config/blob/master/hooks/resolveDependencies.js which tries to install read-package-json, but resolveDependencies.js itself is dependent on read-package-json.
I've moved from Phonegap Build 5.2.0 to 6.1.0, then it started to ignore my preferences and generate minSdkVersion 15+, my preferences were:
<preference name="android-minSdkVersion" value="21" />
<preference name="android-targetSdkVersion" value="23" />
I tried to use this plugin to overwrite sdk version on manifest but it's not working, I've tried both:
<preference name="android-manifest/uses-sdk/@android:minSdkVersion" value="21" />
<preference name="android-manifest/uses-sdk/@android:targetSdkVersion" value="23" />
and
<config-file target="AndroidManifest.xml" parent="/*">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="23" />
</config-file>
without success.
Any thoughts on this?
I have this
<platform name="ios">
<config-file overwrite="true" parent="UISupportedInterfaceOrientations" target="*-Info.plist" platform="ios">
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
</config-file>
<config-file overwrite="true" parent="UISupportedInterfaceOrientations~ipad" target="*-Info.plist" platform="ios">
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
</config-file>
in my config.xml
. When building an android version thought, this happens:
$ cordova build android --release
cordova-custom-config: Applied custom config from config.xml to xxx\platforms\ios\xxx\xxx-Info.plist
This doesn't seem to be right.
When using the following preference:
name="ios-XCBuildConfiguration-VALID_ARCHS" value="arm64 armv7"
The result in project.pbxproj is
VALID_ARCHS = arm64 armv7;
expected result is
VALID_ARCHS = "arm64 armv7";
version 1.2.2
after running $cordova prepare ios --verbose
you see these lines in the output near the end:
cordova-custom-config: Completed npm install
cordova-custom-config: Installed modules
cordova-custom-config: Removed our package.json
cordova-custom-config: Dependency resolution complete
Shortly thereafter you'll notice that your package.json
file at the project level is missing. That's no good. I didn't see this happen before today.
Hi there, I am probably missing something silly, but it does not appear to work for me.
I want to change the AndroidManifest.xml so in my config.xml file I added your Android example xml, and I set the namespace correctly in my widget element.
Nothing changes in the manifest after I run cordova prepare. Looking at the log, Running applyCustomConfig.js
is never called.
I tested your example and it works, same machine, same Cordova CLI and same android platform...
In platform cordova-ios v4.0+, build.xcconfig
already contains Developer entries for CODE_SIGN_IDENTITY
which get incorrectly clobbered by custom configuration tags with buildType="release"
.
While I haven't encountered broken builds from this behavior, I get very nervous when the value iPhone Developer
in build.xcconfig
gets clobbered by my distribution code sign identity value. I expect my distribution code sign identify string to be added only to build-release.xcconfig
. I expect my developer code sign identity string (set by a buildType="debug"
preference) to be what is added to build.xcconfig
(I think? Or would it make more sense for the value in build.xcconfig
be removed and moved to build-debug.xcconfig
?). I wonder if this behavior where buildType="release"
preferences are getting applied to both build-release.xcconfig
and build.xcconfig
for any other XCBuildConfiguration keys?
cordova-ios v4.0 build.xcconfig and build-release.xcconfig
https://github.com/apache/cordova-ios/blob/4.0.0/bin/templates/scripts/cordova/build.xcconfig
https://github.com/apache/cordova-ios/blob/master/bin/templates/scripts/cordova/build-release.xcconfig
build.xcconfig before cordova prepare ios --release --device
:
CODE_SIGN_IDENTITY = iPhone Developer
CODE_SIGN_IDENTITY[sdk=iphoneos*] = iPhone Developer
config.xml:
<preference name="ios-XCBuildConfiguration-CODE_SIGN_IDENTITY" value="iPhone Developer" buildType="debug" quote="none"/>
<preference name="ios-XCBuildConfiguration-CODE_SIGN_IDENTITY" value="iPhone Distribution: {{MY_DISTIBUTION_CODE_SIGN_IDENTITY}}" buildType="release" quote="none"/>
build.xcconfig after cordova prepare ios --release --device
:
CODE_SIGN_IDENTITY = iPhone Distribution: {{MY_DISTIBUTION_CODE_SIGN_IDENTITY}}
CODE_SIGN_IDENTITY[sdk=iphoneos*] = iPhone Developer
build-release.xcconfig before cordova prepare ios --release --device
:
CODE_SIGN_IDENTITY = iPhone Distribution
CODE_SIGN_IDENTITY[sdk=iphoneos*] = iPhone Distribution
config.xml:
<preference name="ios-XCBuildConfiguration-CODE_SIGN_IDENTITY" value="iPhone Developer" buildType="debug" quote="none"/>
<preference name="ios-XCBuildConfiguration-CODE_SIGN_IDENTITY" value="iPhone Distribution: {{MY_DISTIBUTION_CODE_SIGN_IDENTITY}}" buildType="release" quote="none"/>
build-release.xcconfig after cordova prepare ios --release --device
:
CODE_SIGN_IDENTITY = iPhone Distribution: {{MY_DISTIBUTION_CODE_SIGN_IDENTITY}}
CODE_SIGN_IDENTITY[sdk=iphoneos*] = iPhone Developer
I haven't build since 14 days, but today, I don't know why, nothing happens with a cordova build (android or ios) :
$ cordova build android
cordova-custom-config: Installing plugin dependencies...
cordova-custom-config: Skipping auto-restore of config file backup(s) due to config.xml preference
$
I have the problem on 3 different computers (each was able to build 14 days ago), and if I remove cordova-custom-config plugin, it works again. Maybe a problem with the new cordova-android or cordova-ios ?
I've setup my app to use automated code signing ( iOS Developer set for all fields ) so there is no need to use the code signing fields in custom configuration. Is there a way to automate the Team selection (General tab in Xcode) through this plugin?
Greetings again. Our application grabbed your 1.2.4 update and we noticed that when it ran it overwrote our project-level package.json file. Is this something that happened with 1.2.4 or is it more of a timing issue?
Using your example project
While trying to run cordova prepare android --verbose
I always get the below error
My Cordova veriosn 5.0.0
TypeError: undefined is not a function
at getConfigFilesByTargetAndParent (/home/mostafa/workspace/cordova-custom-config-example/plugins/cordova-custom-config/hooks/applyCustomConfig.js:100:19)
at parseConfigFiles (/home/mostafa/workspace/cordova-custom-config-example/plugins/cordova-custom-config/hooks/applyCustomConfig.js:201:27)
at parseConfigXml (/home/mostafa/workspace/cordova-custom-config-example/plugins/cordova-custom-config/hooks/applyCustomConfig.js:114:9)
at updatePlatformConfig (/home/mostafa/workspace/cordova-custom-config-example/plugins/cordova-custom-config/hooks/applyCustomConfig.js:431:26)
at /home/mostafa/workspace/cordova-custom-config-example/plugins/cordova-custom-config/hooks/applyCustomConfig.js:486:17
at arrayEach (/home/mostafa/node_modules/lodash/lodash.js:446:11)
at Function.forEach (/home/mostafa/node_modules/lodash/lodash.js:7482:11)
at applyCustomConfig.init (/home/mostafa/workspace/cordova-custom-config-example/plugins/cordova-custom-config/hooks/applyCustomConfig.js:483:11)
at /home/mostafa/workspace/cordova-custom-config-example/plugins/cordova-custom-config/hooks/resolveDependencies.js:46:11
at installRequiredNodeModules (/home/mostafa/workspace/cordova-custom-config-example/plugins/cordova-custom-config/hooks/resolveDependencies.js:109:7)
May you help on that?
Hello ๐
In the config.xml I have this custom config to change supports-screens
inside the AndroidManifest.xml
<platform name="android">
[.... more code]
<config-file target="AndroidManifest.xml" parent="/*">
<supports-screens android:smallScreens="false"
android:normalScreens="false"
android:largeScreens="true"
android:xlargeScreens="true"
android:requiresSmallestWidthDp="600" />
</config-file>
</platform>
after each cordova prepare
I still have the default value and the custom one is every time added as well
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
[.... more code]
<supports-screens android:largeScreens="true" android:normalScreens="false" android:requiresSmallestWidthDp="600" android:smallScreens="false" android:xlargeScreens="true" />
<supports-screens android:largeScreens="true" android:normalScreens="false" android:requiresSmallestWidthDp="600" android:smallScreens="false" android:xlargeScreens="true" />
Hi Dave,
what about using the special hooknames 'before_plugin_install' and 'before_plugin_uninstall' for setup/removal of your plugin? (see http://cordova.apache.org/docs/en/5.1.1/guide/appdev/hooks/)
Currently you are using 'before_plugin_rm' and 'after_plugin_add'. These will fire each time any plugin is added/removed.
The hooks names mentioned above should only fire, when your plugin is added or removed. This could have massive perfomance impacts on your users cordova build process.
Very nice job, I am glad this plugin exists. :)
I can't find an easy way to map a field I want to modify to its name in the .plist for iOS.
For example, how can I access CFBundleDevelopmentRegion or CFBundleDisplayName ?
Thanks, and keep up the good work!
When applying quote="none"
or quote="key"
to an ios preference, the value is always quoted when it shouldn't.
I think the error could be on https://github.com/dpa99c/cordova-custom-config/blob/1.2.5/hooks/applyCustomConfig.js#L400 . The value written is always quoteEscape(item.value)
when it should be value
.
Hi,
Thanks for making this plugin. I really need this functionality. Unfortunately it breaks my cordova android build with this error:
../platforms/android/build/intermediates/res/armv7/debug/xml/config.xml:43: error: Error parsing XML: unbound prefix
That line says:
<config-file parent="/*" target="AndroidManifest.xml"> <uses-permission android:name="android.permission.CAMERA" /> </config-file>
The root config.xml file used by this installation has the following config platform settings that are used by your plugin:
<platform name="android"> <config-file target="AndroidManifest.xml" parent="/*"> <uses-permission android:name="android.permission.CAMERA" /> </config-file> <preference name="android-manifest/application/@android:name" value="com.joustie.foo.App" /> <icon src="resources/android/icon/drawable-ldpi-icon.png" density="ldpi"/> <icon src="resources/android/icon/drawable-mdpi-icon.png" density="mdpi"/> <icon src="resources/android/icon/drawable-hdpi-icon.png" density="hdpi"/> <icon src="resources/android/icon/drawable-xhdpi-icon.png" density="xhdpi"/> <icon src="resources/android/icon/drawable-xxhdpi-icon.png" density="xxhdpi"/> <icon src="resources/android/icon/drawable-xxxhdpi-icon.png" density="xxxhdpi"/> <splash src="resources/android/splash/drawable-land-ldpi-screen.png" density="land-ldpi"/> <splash src="resources/android/splash/drawable-land-mdpi-screen.png" density="land-mdpi"/> <splash src="resources/android/splash/drawable-land-hdpi-screen.png" density="land-hdpi"/> <splash src="resources/android/splash/drawable-land-xhdpi-screen.png" density="land-xhdpi"/> <splash src="resources/android/splash/drawable-land-xxhdpi-screen.png" density="land-xxhdpi"/> <splash src="resources/android/splash/drawable-land-xxxhdpi-screen.png" density="land-xxxhdpi"/> <splash src="resources/android/splash/drawable-port-ldpi-screen.png" density="port-ldpi"/> <splash src="resources/android/splash/drawable-port-mdpi-screen.png" density="port-mdpi"/> <splash src="resources/android/splash/drawable-port-hdpi-screen.png" density="port-hdpi"/> <splash src="resources/android/splash/drawable-port-xhdpi-screen.png" density="port-xhdpi"/> <splash src="resources/android/splash/drawable-port-xxhdpi-screen.png" density="port-xxhdpi"/> <splash src="resources/android/splash/drawable-port-xxxhdpi-screen.png" density="port-xxxhdpi"/> </platform>
Any idea why android build fails? The AndroidManifest.xml file int he platform directory is correctly updated by your plugin code, but it seems to also alter an 'intermediate' file that is parsed in the android build phase?
Cordova CLI fails on this error. I just installed the plugin via CLI and put in some orientation settings for iOS.
Am I missing anything?
Regards,
Bas
Hi @dpa99c,
The version 1.1.6 is breaking the android builds for us. The error we get is:
/var/lib/jenkins/jobs/Mobile-App-Build/workspace/Cordova/plugins/cordova-custom-config/hooks/applyCustomConfig.js:396
st'), xcode = require('xcode'), tostr = require('tostr'), fileUtils = require(
^
ReferenceError: fileUtils is not defined
at applyCustomConfig.init (/var/lib/jenkins/jobs/Mobile-App-Build/workspace/Cordova/plugins/cordova-custom-config/hooks/applyCustomConfig.js:400:79)
Any idea why?
right now you can set a value in build preferences, but when it comes to lists of things (ie header search paths) you overwrite the whole list with a flat value. it would be cool if we had a syntax for pushing an item to the list of it isn't present
The package.json doesn't specify a version for lodash, so when lodash was updated to 4.0.0 yesterday this plugin broke since the function "indexBy" was renamed "keyBy".
We have two platform Android and iOS. But no every developer has mac so not every one has xcode installed. Therefore I suggest the plugin will keep working even if failed to find xcode module.
Thanks
By default an ios-XCBuildConfiguration
preference tag without a quote
attribute renders the key and value into xcconfig file surrounded by double quotes. For example, the preference
<preference name="ios-XCBuildConfiguration-ENABLE_BITCODE" value="NO"/>
renders this line in xcconfig
"ENABLE_BITCODE" = "NO"
For me (using platform cordova-ios 3.9.2), when building with cordova build ios --device
this quoted entry throws an error (on build-debug.xcconfig
):
Ignoring configuration file '/PATH_TO_CORDOVA_APP/platforms/ios/cordova/build-debug.xcconfig' because it could not be loaded.
Reason: File could not be parsed due to an error: String '"ENABLE_BITCODE" = "NO"' could not be parsed: '"ENABLE_BITCODE"' is not a legal macro nameBuild settings from command line
Similarly, cordova build ios --release --device
throws an error (on build-release.xcconfig
):
Ignoring configuration file '/PATH_TO_CORDOVA_APP/platforms/ios/cordova/build-release.xcconfig' because it could not be loaded.
Reason: File could not be parsed due to an error: String '"ENABLE_BITCODE" = "NO"' could not be parsed: '"ENABLE_BITCODE"' is not a legal macro nameBuild settings from command line
I was able to resolve my build issues by using the quote
attribute in my preference in config.xml
:
<preference name="ios-XCBuildConfiguration-ENABLE_BITCODE" value="NO" quote="none"/>
I believe quote="none" should be the default setting.
I had to manually install read-package-json through npm to finally be able to install this plugin.
The quote
attribute which allows a user to configure in the ios-XCBuildConfiguration
preference tag how xcconfig lines get rendered (introduced in 6047030) is very useful, but I was unaware of its existence until I read the commit history and the source code.
I recommend you add documentation and an example of this attribute to the readme.
I'm trying to get this plugin working with the ultimate goal of changing the theme to Material Dark on Android. I started by trying to change the theme to the one used in your example config.xml, but I get the following build error:
:processDebugResources/Users/sarah/Development/myapp/platforms/android/res/xml/config.xml:21:84-119 : AAPT: No resource found that matches the given name (at 'value' with value '@android:style/Theme.Red.NoTitleBar')
I incorporated the items from your readme one at a time, and I was able to build and run my app successfully after making the following two:
<widget
id="com.asdfasdfasdf.myapp"
version="2.0.2"
xmlns="http://www.w3.org/ns/widgets"
xmlns:cdv="http://cordova.apache.org/ns/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<widget
id="com.bla.myapp"
version="2.0.2"
xmlns="http://www.w3.org/ns/widgets"
xmlns:cdv="http://cordova.apache.org/ns/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<name>bla</name>
<description>
Bla
</description>
<author email="[email protected]" href="http://www.bla.com">
bla
</author>
<content src="index.html" />
<!-- from https://github.com/dpa99c/cordova-custom-config#removable-preferences-via-backuprestore -->
<preference name="cordova-custom-config-autorestore" value="true" />
<preference name="android-minSdkVersion" value="19" />
...
Once everything built and ran properly with those changes, I added one of the lines from your Android example to my config.xml. Here's the entire Android section of config.xml:
<platform name="android">
<preference name="android-manifest/application/activity/@android:theme" value="@android:style/Theme.Red.NoTitleBar" />
<allow-intent href="market:*" />
<icon src="www/res/icon/android/icon_48_mdpi.png" density="ldpi" />
<icon src="www/res/icon/android/icon_48_mdpi.png" density="mdpi" />
<icon src="www/res/icon/android/icon_72_hdpi.png" density="hdpi" />
<icon src="www/res/icon/android/icon_96_xhdpi.png" density="xhdpi" />
<icon src="www/res/icon/android/icon_144_xxhdpi.png" density="xxhdpi" />
<icon src="www/res/icon/android/icon_192_xxxhdpi.png" density="xxxhdpi" />
</platform>
After adding that, building gives me the error I mentioned above:
:processDebugResources/Users/sarah/Development/myapp/platforms/android/res/xml/config.xml:21:84-119 : AAPT: No resource found that matches the given name (at 'value' with value '@android:style/Theme.Red.NoTitleBar')
Can you point me in the right direction? I'm not sure what I'm doing wrong. I'm running on a Nexus 6P with Android Marshmallow. Cordova is 6.2.0 and the Android platform version is 5.1.1.
Also, thank you for making this plugin! It looks excellent and well documented, and I look forward to getting it working. =)
I am currently trying to just set one additional attribute for the <appliction>
config.
That attribute is android:name="MainApp"
. However:
<config-file target="AndroidManifest.xml">
<application android:name="MainApplication" />
</config-file>
causes the build to replace the whole application
tag.
Is there a possibility to let the build process merge this attribute into the existing config?
I have been successfully using version 1.1.4 of this plugin to set the 2 ios preferences as shown below.
I just tried to update to the 1.1.5 version of the plugin and now neither of my preference settings are taking place (they don't end up in the platforms/ios/*.xcodeproj/project.pbxproject file).
<platform name="ios">
<preference
name="ios-XCBuildConfiguration-PRODUCT_NAME" value="'Mobile App'" />
<preference
name="ios-XCBuildConfiguration-IPHONEOS_DEPLOYMENT_TARGET" value="9.0" />
</platform>
When I install the plugin into my Cocoon project, without even making any config.xml changes, the app loses its icon, splash screen and orientation. Those are just a few observations; I'm assuming it's completely ignoring all XML.
I've tried so many tests to get around this and now out of options.
Any ideas at all?
Thanks,
Malc
Example where this currently breaks:
<preference name="ios-XCBuildConfiguration-LD_RUNPATH_SEARCH_PATHS" value="@executable_path/Frameworks" />
needs to be changed to
<preference name="ios-XCBuildConfiguration-LD_RUNPATH_SEARCH_PATHS" value=""@executable_path/Frameworks"" />
or else it corrupts the pbxproj file
cordova displays a warning when using the plugin:
package.json cordova-custom-config@1.1.3 No license field.
You should add follwing field to avoid the warning:
"license": "MIT"
2 error examples I got:
Error: Cannot find module 'tostr'
Error: Cannot find module 'elementtree'
The plugin works fine if I add the plugin after cordova platform add
Is this necessary or is there something else wrong?
Developing in visual studio 2015 for both Android and iOS.
When building for Android only the preference in the iOS platform block is still run.
i.e.
<platform name="ios">
<preference name="ios-XCBuildConfiguration-ENABLE_BITCODE" value="NO" />`
<platform>
This does not seem to occur when it comes to configuration blocks.
When the update error occurs, compilation for android breaks.
<preference name="cordova-custom-config-stoponerror" value="false"/>
does not seem to remedy the issue.
As far as I can tell , the reason why the error occurs is because the file does not exist on the currently executing system, and it executes fine when building for iOS specifically as then the plugin is executed and run remotely on our Mac-buildmachine.
So have i stumbled up on a bug or is this working as intended?
Thank you for this great plugin.
With (the newest) Cordova CLI 5.3.1 and Cordova-Android 4.1.0 some preferences are not applied to the android manifest. We tracked this down to the following root cause:
In https://github.com/dpa99c/cordova-custom-config/blob/master/hooks/applyCustomConfig.js#L30 and the following lines you assume android:name="CordovaApp", but the cordova guys renamed the activity to 'MainActivity'.
This issue may be relevant for cli users only, I haven't tried to reproduce it on phonegap build service. The provided code changes should work with cli and pgb.
To support both activity names you could apply the following changes to your code:
/* Global object that defines the available custom preferences for each platform.
Maps a config.xml preference to a specific target file, parent elements (first match will be used), and destination attribute or element
*/
var preferenceMappingData = {
'android': {
'android-manifest-hardwareAccelerated': {target: 'AndroidManifest.xml', parent: ['./'], destination: 'android:hardwareAccelerated'},
'android-installLocation': {target: 'AndroidManifest.xml', parent: ['./'], destination: 'android:installLocation'},
'android-activity-hardwareAccelerated': {target: 'AndroidManifest.xml', parent: ['application'], destination: 'android:hardwareAccelerated'},
'android-configChanges': {target: 'AndroidManifest.xml', parent: ['application/activity[@android:name=\'CordovaApp\']', 'application/activity[@android:name=\'MainActivity\']'], destination: 'android:configChanges'},
'android-launchMode': {target: 'AndroidManifest.xml', parent: ['application/activity[@android:name=\'CordovaApp\']', 'application/activity[@android:name=\'MainActivity\']'], destination: 'android:launchMode'},
'android-theme': {target: 'AndroidManifest.xml', parent: ['application/activity[@android:name=\'CordovaApp\']', 'application/activity[@android:name=\'MainActivity\']'], destination: 'android:theme'},
'android-windowSoftInputMode': {target: 'AndroidManifest.xml', parent: ['application/activity[@android:name=\'CordovaApp\']', 'application/activity[@android:name=\'MainActivity\']'], destination: 'android:windowSoftInputMode'}
},
'ios': {}
};
function updateAndroidManifest(targetFilePath, configItems) {
var tempManifest = fileUtils.parseElementtreeSync(targetFilePath),
root = tempManifest.getroot();
_.each(configItems, function (item) {
// if parent is not found on the root, child/grandchild nodes are searched
var parentEl,
data = item.data,
childSelector = item.destination,
childEl;
_.each(item.parent, function(parentSelector){
if(parentEl)
return;
parentEl = root.find(parentSelector) || root.find('*/' + parentSelector);
});
if(!parentEl) {
return;
}
if(item.type === 'preference') {
parentEl.attrib[childSelector] = data.attrib['value'];
} else {
// since there can be multiple uses-permission elements, we need to select them by unique name
if(childSelector === 'uses-permission') {
childSelector += '[@android:name=\'' + data.attrib['android:name'] + '\']';
}
childEl = parentEl.find(childSelector);
// if child element doesnt exist, create new element
if(!childEl) {
childEl = new et.Element(item.destination);
parentEl.append(childEl);
}
// copy all config.xml data except for the generated _id property
_.each(data, function (prop, propName) {
if(propName !== '_id') {
childEl[propName] = prop;
}
});
}
});
fs.writeFileSync(targetFilePath, tempManifest.write({indent: 4}), 'utf-8');
}
That's it. Now your plugin supports 'old' and 'new' activity names.
Sorry for not providing a pull request for this, but I'm a litlle in hurry these days.
Felix
This looks like a good replacement for the phonegap-build equivalent but a quick read of your documentation shows no support for removing configuration elements. For example, to remove a bunch of permissions I would do in phonegap-build:
<gap:config-file platform="android" parent="/manifest" mode="delete">
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-feature android:name="android.hardware.camera" android:required="false"/>
</gap:config-file>
Could this be added?
Thank you.
right now this doesnt write to xcconfig files, so on archive actions the settings dont have any effect
Lodash seems to move fast. I get the following error.
cordova-custom-config: Error updating config for platform 'android': keyBy is not a function
What would be the best fix for this?
Hi.
Got a problem on iOS platform, don't really know if the problem is plugin related or cordova, but I take my chance here.
When I tried to install the plugin, it fails about missing some .xconfig file. Here are the logs :
platform add ios --verbose
cordova-custom-config: package.json already exists
cordova-custom-config: Copied existing package.json to package.json.tmp
cordova-custom-config: Copying package.json
cordova-custom-config: Copied package.json
cordova-custom-config: Installing plugin dependencies...
cordova-custom-config: Running npm install
cordova-custom-config: Completed npm install
cordova-custom-config: Installed modules
cordova-custom-config: package.json.tmp exists
cordova-custom-config: Overwrote our package.json with original package.json.tmp
cordova-custom-config: Removing package.json.tmp
cordova-custom-config: Removed package.json.tmp
cordova-custom-config: Dependency resolution complete
No version supplied. Retrieving version from config.xml...
Adding ios project...
Running command: /Users/thomas/.cordova/lib/npm_cache/cordova-ios/3.8.0/package/bin/create --cli /Users/thomas/dev/html/rando/platforms/ios com.latitude.rando Rando
iOS project created with [email protected]
Command finished with error code 0: /Users/thomas/.cordova/lib/npm_cache/cordova-ios/3.8.0/package/bin/create --cli,/Users/thomas/dev/html/rando/platforms/ios,com.latitude.rando,Rando
cordova-custom-config: Running restoreBackups.js
cordova-custom-config: package.json already exists
cordova-custom-config: Copied existing package.json to package.json.tmp
cordova-custom-config: Copying package.json
cordova-custom-config: Copied package.json
cordova-custom-config: Installing plugin dependencies...
cordova-custom-config: Running npm install
cordova-custom-config: Completed npm install
cordova-custom-config: Installed modules
cordova-custom-config: package.json.tmp exists
cordova-custom-config: Overwrote our package.json with original package.json.tmp
cordova-custom-config: Removing package.json.tmp
cordova-custom-config: Removed package.json.tmp
cordova-custom-config: Dependency resolution complete
cordova-custom-config: Checking to see if there are backups to restore...
cordova-custom-config: Restored backup of 'project.pbxproj' to :/Users/thomas/Dev/html/rando/platforms/ios/Rando.xcodeproj/project.pbxproj
cordova-custom-config: Finished restoring backups
Generating config.xml from defaults for platform "ios"
Calling plugman.prepare for platform "ios"
Preparing ios project
Processing configuration changes for plugins.
Iterating over installed plugins: []
Writing out cordova_plugins.js...
Wrote out iOS Bundle Identifier to "com.latitude.rando"
Wrote out iOS Bundle Version to "0.0.1"
Copying icon from /Users/thomas/dev/html/rando/resources/ios/icon/icon-60.png to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/icons/icon-60.png
Copying icon from /Users/thomas/dev/html/rando/resources/ios/icon/[email protected] to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/icons/[email protected]
Copying icon from /Users/thomas/dev/html/rando/resources/ios/icon/[email protected] to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/icons/[email protected]
Copying icon from /Users/thomas/dev/html/rando/resources/ios/icon/icon-76.png to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/icons/icon-76.png
Copying icon from /Users/thomas/dev/html/rando/resources/ios/icon/[email protected] to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/icons/[email protected]
Copying icon from /Users/thomas/dev/html/rando/resources/ios/icon/icon-small.png to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/icons/icon-small.png
Copying icon from /Users/thomas/dev/html/rando/resources/ios/icon/[email protected] to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/icons/[email protected]
Copying icon from /Users/thomas/dev/html/rando/resources/ios/icon/icon-40.png to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/icons/icon-40.png
Copying icon from /Users/thomas/dev/html/rando/resources/ios/icon/[email protected] to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/icons/[email protected]
Copying icon from /Users/thomas/dev/html/rando/resources/ios/icon/icon.png to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/icons/icon.png
Copying icon from /Users/thomas/dev/html/rando/resources/ios/icon/[email protected] to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/icons/[email protected]
Copying icon from /Users/thomas/dev/html/rando/resources/ios/icon/icon-72.png to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/icons/icon-72.png
Copying icon from /Users/thomas/dev/html/rando/resources/ios/icon/[email protected] to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/icons/[email protected]
Copying icon from /Users/thomas/dev/html/rando/resources/ios/icon/icon-50.png to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/icons/icon-50.png
Copying icon from /Users/thomas/dev/html/rando/resources/ios/icon/[email protected] to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/icons/[email protected]
Copying splash from /Users/thomas/dev/html/rando/resources/ios/splash/Default~iphone.png to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/splash/Default~iphone.png
Copying splash from /Users/thomas/dev/html/rando/resources/ios/splash/Default@2x~iphone.png to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/splash/Default@2x~iphone.png
Copying splash from /Users/thomas/dev/html/rando/resources/ios/splash/Default-Portrait~ipad.png to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/splash/Default-Portrait~ipad.png
Copying splash from /Users/thomas/dev/html/rando/resources/ios/splash/Default-Portrait@2x~ipad.png to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/splash/Default-Portrait@2x~ipad.png
Copying splash from /Users/thomas/dev/html/rando/resources/ios/splash/Default-Landscape~ipad.png to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/splash/Default-Landscape~ipad.png
Copying splash from /Users/thomas/dev/html/rando/resources/ios/splash/Default-Landscape@2x~ipad.png to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/splash/Default-Landscape@2x~ipad.png
Copying splash from /Users/thomas/dev/html/rando/resources/ios/splash/Default-568h@2x~iphone.png to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/splash/Default-568h@2x~iphone.png
Copying splash from /Users/thomas/dev/html/rando/resources/ios/splash/Default-667h.png to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/splash/Default-667h.png
Copying splash from /Users/thomas/dev/html/rando/resources/ios/splash/Default-736h.png to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/splash/Default-736h.png
Copying splash from /Users/thomas/dev/html/rando/resources/ios/splash/Default-Landscape-736h.png to /Users/thomas/dev/html/rando/platforms/ios/Rando/Resources/splash/Default-Landscape-736h.png
iOS Product Name has not changed (still "Rando")
Running command: /Users/thomas/dev/html/rando/hooks/after_prepare/010_add_platform_class.js /Users/thomas/dev/html/rando
add to body class: platform-ios
Command finished with error code 0: /Users/thomas/dev/html/rando/hooks/after_prepare/010_add_platform_class.js /Users/thomas/dev/html/rando
cordova-custom-config: Running applyCustomConfig.js
cordova-custom-config: package.json already exists
cordova-custom-config: Copied existing package.json to package.json.tmp
cordova-custom-config: Copying package.json
cordova-custom-config: Copied package.json
cordova-custom-config: Installing plugin dependencies...
cordova-custom-config: Running npm install
cordova-custom-config: Completed npm install
cordova-custom-config: Installed modules
cordova-custom-config: package.json.tmp exists
cordova-custom-config: Overwrote our package.json with original package.json.tmp
cordova-custom-config: Removing package.json.tmp
cordova-custom-config: Removed package.json.tmp
cordova-custom-config: Dependency resolution complete
cordova-custom-config: Backup exists for 'project.pbxproj' at: /Users/thomas/Dev/html/rando/plugins/cordova-custom-config/backup/ios/project.pbxproj
cordova-custom-config: Applied custom config from config.xml to /Users/thomas/dev/html/rando/platforms/ios/Rando.xcodeproj/project.pbxproj
cordova-custom-config: Reading build.xcconfig
cordova-custom-config: Reading build-extras.xcconfig
cordova-custom-config: Error updating config for platform 'ios': ENOENT: no such file or directory, open '/Users/thomas/dev/html/rando/platforms/ios/cordova/build-extras.xcconfig'
undefined
Any idea of the problem ?
Thanks !
Hi!,
The hook no write changes in file. I change the line:
fs.writeFileSync(targetFilePath, tempManifest.write({indent: 4}), 'utf-8');
to
fs.writeFileSync(targetFilePath, tempManifest.write({indent: 4}), 'utf-8', (err) => {if(err) throw err;});
and this work.
Regards
Using version 1.2.4 with [email protected]. Have added a few config-file entries to try and add/overwrite entries in our *-Info.plist file and they are not appearing. We even tried just using one of your examples. Here's the output on the console during $cordova prepare ios --verbose
:
cordova-custom-config: Write to plist; key=NSLocationAlwaysUsageDescription; value='This app requires constant access to your location in order to track your position, even when the screen is off.'
However, when you look at the plist file you see that the entry was not added.
$ cordova prepare android
cordova-custom-config: Error updating config for platform 'android': _.indexBy is not a function
cordova-custom-config: Error updating config for platform 'ios': _.indexBy is not a function
$ cordova plugin remove cordova-custom-config
Uninstalling cordova-custom-config from android
Uninstalling cordova-custom-config from ios
Error: Expected "/* Begin ", "/* End ", """ or [A-Za-z0-9_.] but "<" found.
$ cordova plugin add cordova-custom-config
Fetching plugin "cordova-custom-config@~1.1.8" via npm
Installing "cordova-custom-config" for android
Installing "cordova-custom-config" for ios
Failed to install 'cordova-custom-config':undefined
Error: Expected "/* Begin ", "/* End ", """ or [A-Za-z0-9_.] but "<" found.
Any ideas?
I recently upgraded my Cordova project from Android 4.1.1 to Android 5.1.1.
I performed a "cordova platform remove android" and shortly after, I added back the platform with the new android version.
Upon building the project I noticed my AndroidManfiest.xml was still pointing to the old targetSDK. I couldn't figure out why. As it turns out, this plugin had a backup of the old Android Manifest. I'm not sure how you are maintaining this backup, but it should be removed anytime the platform is removed. (and probably updated as well?)
I did see the preference, cordova-custom-config-autorestore, which I will implement, but I wanted to at least report this.
C:\dev\code\tippy-app>cordova plugin add cordova-custom-config
Fetching plugin "cordova-custom-config" via npm
Installing "cordova-custom-config" for android
cordova-custom-config: Installing plugin dependencies...
Running command: "C:\Program Files\nodejs\node.exe" C:\dev\code\tippy-app\hooks\after_plugin_add\010_register_plugin.js C:\dev\code\tippy-app
Running command: "C:\Program Files\nodejs\node.exe" C:\dev\code\tippy-app\hooks\after_plugin_add\register_plugins.js C:\dev\code\tippy-app
C:\dev\code\tippy-app\hooks\after_plugin_add\register_plugins.js:12
if (! _.contains(packageJSON.cordovaPlugins, plugin)) {
^
TypeError: _.contains is not a function
at C:\dev\code\tippy-app\hooks\after_plugin_add\register_plugins.js:12:11
at arrayEach (C:\dev\code\tippy-app\node_modules\lodash\lodash.js:474:11)
at Function.forEach (C:\dev\code\tippy-app\node_modules\lodash\lodash.js:7633:11)
at Object. (C:\dev\code\tippy-app\hooks\after_plugin_add\register_plugins.js:11:3)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:140:18)
Error: Hook failed with error code 1: C:\dev\code\tippy-app\hooks\after_plugin_add\register_plugins.js
the backup functionality is really problematic if you are making manual changes to the xcode config
I was very happy to find this plugin, but I'd like to add resources in res/values/strings.xml
.
Could it be allowed?
Well, that part isn't hard: there is a check for the filename to be 'AndroidManifest.xml', which can be removed.
However, the object PLATFORM_CONFIG_FILES
's contents would need to be determined either by looking at the backup directory's contents, or the list of modified files in config.xml
.
Here is the diff of the changes I made in order for it to work for one extra file:
cordova-custom-config-additionalfile.txt
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.