Reputation: 2187
I have config.xml with following line inside.
<widget id="dev.apk" version="2.5-dev" android-versionCode="20500-dev">
I'd like to change value of attributes 'version', 'id', and 'android-versionCode' in my Bash script.
In the script I have access to ID, VERSION an VERSION_CODE variables, like this:
ID ="release.apk"
VERSION="2.5"
VERSION_CODE="20500"
I'd like to use xmlstarlet or sed. What would be the best way?
Update
My .xml file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" id="app" version="2.5" android-versionCode="20500">
<name>App title</name>
<description>Dummy dummy text.</description>
</widget>
Upvotes: 2
Views: 1609
Reputation: 185690
You can do this to edit in-place the xml file :
Example for id
attribute :
xmlstarlet edit -L -u "/_:widget/@id" -v "$ID" file.xml
You just have now to adapt this snippet for the other ones.
Upvotes: 2
Reputation: 549
You could do something like the below in sed.
sed -i "s|dev.apk|$ID|g" test.xml
But if you are already using a build tool you might want to have a look at replacing your values with placeholder and having targeted environment files
I believe that there is some placeholder support in gradle
http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger
Upvotes: 0