Reputation: 19804
PhoneGap Build provides a service (currently free during beta) where they take your HTML+JS+CSS source, along with an XML file to configure build options (config.xml), and do server-side builds for all supported platforms (iOS, Android, Blackberry, Symbian, WebOS), which is a huge time saver and saves me tons of money on headache medicine.
Unfortunately, there is inconsistent behavior with the way links to external websites work:
Currently in order to have links open in an external browser, it requires uploading different code to PhoneGap Build. For iOS the domain must be whitelisted, and for Android the domain must be unlisted.
You could make it consistent by adding an attribute to the access tag, like includeForAndroid="false", which would NOT include the access tag contents on Android, so that links would open in an external browser, just like on iOS.
Config.xml docs; and here's a relevant blog post.
While there is a proposed fix by an employee, it has yet to be made and released in the product:
We're hoping to get this straightened out in Cordova open source project: in the meantime, for PhoneGap Build, I'm thinking something like this:
<access origin="*" onlyInBrowser="true" />
That will not include the tag on Android, but will on iOS.
Until this change is made and available in the product, the work-around is to make two zip files that I will upload: one for Android (without the access tags) and one for iOS (with the access tags). Not ideal, but it's what must be done for consistent app behavior.
I'm already using ANT to automate many tasks within this project, so it would be ideal if ANT could do the config.xml updates for me too.
For reference, here's my ANT code that would build the two zips:
<target name="BUILD-ZIP" depends="verify-using-minified-js,prepare-for-build">
<tstamp>
<format property="build.tstamp" pattern="yyyy-MM-dd__HH-mm-ss" />
</tstamp>
<antcall target="zip-ios">
<param name="tstamp" value="${build.tstamp}" />
</antcall>
<!-- build android second so that we can just remove the access tags -->
<antcall target="zip-android">
<param name="tstamp" value="${build.tstamp}" />
</antcall>
</target>
<target name="zip-ios">
<zip destfile="${dir.pkg.phonegap}${tstamp}-apple.zip">
<zipfileset dir="${dir.pkg.tmp}">
<exclude name="build.xml" />
<exclude name="build.properties" />
<exclude name="settings.xml" />
<exclude name=".project" />
<exclude name="**/*.psd" />
<exclude name="assets/js/app.js" />
<exclude name="assets/js/cordova-1.5.0.js" />
</zipfileset>
</zip>
</target>
<target name="zip-android">
<!-- before building android zip, get rid of the <access> tags -->
<zip destfile="${dir.pkg.phonegap}${tstamp}-android.zip">
<zipfileset dir="${dir.pkg.tmp}">
<exclude name="build.xml" />
<exclude name="build.properties" />
<exclude name="settings.xml" />
<exclude name=".project" />
<exclude name="**/*.psd" />
<exclude name="assets/js/app.js" />
<exclude name="assets/js/cordova-1.5.0.js" />
</zipfileset>
</zip>
</target>
<target name="prepare-for-build">
<!-- increment build number -->
<propertyfile file="build.properties">
<entry key="version.build.number" type="int" operation="+" default="1"/>
</propertyfile>
<property file="build.properties"/>
<echo message="BUILD NUMBER: ${version.build.number}"/>
<delete includeemptydirs="true" verbose="false">
<fileset dir="${dir.pkg.tmp}" includes="**/*"/>
</delete>
<filter token="BUILD_NUMBER" value="${version.build.number}" />
<filter token="VERSION_MAJOR" value="${version.major}" />
<filter token="VERSION_MINOR" value="${version.minor}" />
<copy todir="${dir.pkg.tmp}" verbose="true" overwrite="true" filtering="true">
<fileset dir="${dir.dev}" includes="**/*" />
</copy>
</target>
There's a comment in there, in the zip-android
target:
<!-- before building android zip, get rid of the <access> tags -->
This is where I want to do the replacement. I've tried using the <filter>
task as well as <replace>
and <replaceRegExp>
, but I can't seem to find a way to do it, and it all boils down to the fact that I need to replace the string: <access ... />
and none of these replacement methods seem to allow <
or >
in the token/match/etc attributes. I've tried using CDATA, but couldn't get that working either.
The closest I've come, in that ANT doesn't throw any errors, is this:
<replace file="${dir.pkg.tmp}config.xml" failOnNoReplacements="true">
<replacetoken>
<![CDATA[<access origin="http://example.com" subdomains="true" />]]>
</replacetoken>
</replace>
In theory, this would replace the specified <access ... />
tag with an empty string, because I've omitted the value
attribute.
Unfortunately, it fails because of the failOnNoReplacements
attribute and the fact that, for whatever reason, it's not doing any replacements.
Is this possible? If so, what am I doing wrong?!
Upvotes: 2
Views: 7578
Reputation: 6428
The Ant replace task will work if you encode the elements of the XML string in both the token and value... for example:
In config.xml
<option name="some.unwanted.configuration" />
In build.xml
<replace file="${build.dir}/config.xml"
token="<option name="some.unwanted.configuration" />"
value="<!-- unwanted configuration removed -->"
/>
results in
<!-- unwanted configuration removed -->
Upvotes: 4
Reputation: 10377
When dealing with xml i recommend the xmltask.
For your demand see: xml task manual replace
a little Xpath knowledge will come in handy, see:
http://zvon.org/xxl/XPathTutorial/
http://www.w3schools.com/xpath/
Upvotes: 0
Reputation: 19804
Ha, I managed to put together a solution that gets around the blocking of angle brackets.
In config.xml:
<!--access_tag1_here-->
In build.xml:
<replace
file="${dir.pkg.tmp}config.xml"
failOnNoReplacements="true"
token="!--access_tag1_here--"
value="access origin='http://example.com' subdomains='true' /"
/>
This transforms the comment into the necessary access tag.
I switched my zip order so that Android now goes first while the comments are still comments, and then the iOS zip process inserts the access tags.
Upvotes: 1