Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommended way of creating test version of Android app

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?

like image 907
Tormod Fjeldskår Avatar asked Dec 05 '25 11:12

Tormod Fjeldskår


1 Answers

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:

  1. Create a new Build Configuration, Test, for your solution.
  2. Define a new Conditional compilation symbol, TEST, in your project.
  3. Rename your existing AndroidManifest.xml to AndroidManifest-Template.xml
  4. 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>
    
  5. 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>
    
  6. 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 :)

like image 174
khellang Avatar answered Dec 06 '25 23:12

khellang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!