I use Cordova with two platforms ios and android. When I change something in my
Project/config.xml
it will be merged into
Project/platforms/android/res/xml/config.xml
Project/platforms/ios/Project/config.xml
after doing cordova build.
How can I set platform specific settings which will not be overwritten with cordova build?
Define your platform specific configuration inside platform elements.
<platform name="android">
<preference name="Fullscreen" value="true" />
...
</platform>
See bottom of: http://cordova.apache.org/docs/en/4.0.0/config_ref_index.md.html
And if you use an older version of Cordova, consider updating as many critical issues were fixed.
You need a cordova hook. I strongly recommend you see this link: Cordova Hooks
More specifically:
mkdir -p hooks/after_prepare
touch hooks/after_prepare/change_my_configxml.sh
chmod 755 hooks/after_prepare/change_my_configxml.sh
edit hooks/after_prepare_change_my_configxml.sh
#!/bin/bash
echo ${CORDOVA_VERSION};
echo ${CORDOVA_PLATFORMS};
echo ${CORDOVA_PLUGINS};
echo ${CORDOVA_HOOK};
echo ${CORDOVA_CMDLINE};
# == put commands to make your config xml changes here ==
# == replace this statement with your own ==
sed "s/index\.html/http:\/\/my.example.com\?platform=ios\&cordova=3.4.0/" platforms/ios/www/config.xml > config.tmp && mv -f -v config.tmp platforms/ios/www/config.xml
Note that cordova hooks were originally placed in .cordova/hooks/... , but recently they have moved to a top-level hooks/ folder.
Here is a fully working script to create and run two slightly different cordova apps. Interestingly, the attribute in the iOS platform folder's config.xml seems to get ignored, so this script updates the top-level config.xml when dealing with iOS.
#!/bin/bash
# ==== Create cordova apps with different URLs for android and iOS
cordova create appFolder com.example.myApp "My App"
cd appFolder/
cordova platform add ios
cordova platform add android
# ==== make an after_prepare hook script
mkdir -p hooks/after_prepare
touch hooks/after_prepare/change_my_configxml.sh
chmod 755 hooks/after_prepare/change_my_configxml.sh
# ==== start of hook script content ====
echo '#!/bin/bash
echo "CORDOVA_VERSION: ${CORDOVA_VERSION}";
echo "CORDOVA_PLATFORMS: ${CORDOVA_PLATFORMS}";
echo "CORDOVA_PLUGINS: ${CORDOVA_PLUGINS}";
echo "CORDOVA_HOOK: ${CORDOVA_HOOK}";
echo "CORDOVA_CMDLINE: ${CORDOVA_CMDLINE}";
# == put commands to make your config xml changes here ==
# == replace these statement with your own ==
if [ ! -f platforms/android/res/xml/config.xml ]
then
cp -v -f config.xml platforms/android/res/xml/config.xml;
fi
if [[ ${CORDOVA_PLATFORMS} == android ]]; then
sed -E "s/<content src=\"[^\"]+\"/<content src=\"http:\/\/www.google.com\/search\?q=Google%20Nexus%205\&hl=xx-bork\"/" platforms/android/res/xml/config.xml > config.tmp && mv -f -v config.tmp platforms/android/res/xml/config.xml
fi
if [[ ${CORDOVA_PLATFORMS} == ios ]]; then
sed -E "s/<content src=\"[^\"]+\"/<content src=\"http:\/\/www.google.com\/search\?q=iPad%20Retina\&hl=xx-bork\"/" config.xml > config.tmp && mv -f -v config.tmp config.xml
fi
' > hooks/after_prepare/change_my_configxml.sh
# ==== end of hook script content ====
cordova prepare android
cordova build android
cordova emulate android
cordova prepare ios
cordova build ios
cordova emulate ios
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With