Reputation: 6002
We have an Android app built with Mono for Android, and now we have desire to make a deployable test version for use in acceptance testing. It is important that the production version remains on the device and keeps working. What is the recommended way of creating a test build without causing interference like package name collisions?
Upvotes: 3
Views: 785
Reputation: 18102
This solution applies to Mono for Android and allows you to change the package name of an application based on build configuration in Visual Studio:
AndroidManifest.xml
to AndroidManifest-Template.xml
Create two .xslt files in the Properties folder:
manifest-transform.xslt:
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="/manifest/@package">
<xsl:attribute name="package">
<xsl:value-of select="'<your.test.package.name.here>'" />
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
manifest-copy.xslt:
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Add two XslTransformation
tasks to the BeforeBuild
target of your project file:
<Target Name="BeforeBuild">
<XslTransformation
Condition="'$(Configuration)|$(Platform)' != 'Test|AnyCPU'"
XslInputPath="Properties\manifest-copy.xslt"
XmlInputPaths="Properties\AndroidManifest-Template.xml"
OutputPaths="Properties\AndroidManifest.xml" />
<XslTransformation
Condition="'$(Configuration)|$(Platform)' == 'Test|AnyCPU'"
XslInputPath="Properties\manifest-transform.xslt"
XmlInputPaths="Properties\AndroidManifest-Template.xml"
OutputPaths="Properties\AndroidManifest.xml" />
</Target>
Use the TEST symbol for conditional code:
#if TEST
[Application(
Label = "App Test",
Theme = "@style/Theme.App.Test",
Icon = "@drawable/ic_launcher_test")]
#else
[Application(
Label = "App",
Theme = "@style/Theme.App",
Icon = "@drawable/ic_launcher")]
#endif
You can now switch between test and regular app by changing build config :)
Upvotes: 4
Reputation: 9982
Changing the package name should probably be enough to keep things from conflicting, unless you are writing data to a hardcoded location, which would also need to be changed.
Upvotes: 0