Recommended way to create a test version of an Android application

We have an Android app built with Mono for Android, and now we have a desire to create a deployable test run for use in acceptance testing. It is important that the production version stays on the device and continues to run. What is the recommended way to create a test build without interferences such as package name collisions?

+3


source to share


2 answers


This solution is specific to Mono for Android and allows you to change the application package name based on the build configuration in Visual Studio:

  • Create a new build configuration Test for your solution.
  • Define a new conditional compilation symbol TEST in your project .
  • Rename the existing one AndroidManifest.xml

    toAndroidManifest-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 tasks XslTransformation

    to the target of BeforeBuild

    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
    
          



Now you can switch between test and regular application by changing your build config :)

+4


source


Changing the package name should probably be enough to prevent things from conflicting, unless you are writing data to a hardcoded location that needs to be changed as well.



0


source







All Articles