Question

We have a menu on an activity that allows beta users to switch between several testing/staging database/REST servers. On release I would like to remove this menu from even being seen. I don't want a variable in code that I have to modify by hand. I want our CI to do this for me. Just not sure the best way to dynamically build to remove this. I was thinking of adding debuggable in the manifest, and then when Jenkins builds it for release it changes the manifest debuggable to false which in turn the code will hide the menu from users. Is this the best way or is there a better way? (maybe use testOnly in manifest?)

Was it helpful?

Solution

Currently I am using the debuggable attribute in the manifest which is not initially set in file since Eclipse frowns on this. Then in my ant script I have created a custom_rules.xml where I set the property in the manifest manually based on the targets false if release and true if debug version.

<target name="-set-debug-files" depends="-set-mode-check">
.....
    <!-- alter the app manifest to reflect the testing state -->
    <property name="match.start" value="android:debuggable="/>
    <property name="match.end" value=">"/>
    <replaceregexp file="AndroidManifest.xml"
               match="${match.start}.*${match.end}"
               replace="${match.start}&quot;true&quot;${match.end}">
    </replaceregexp>

    <echo level="info">${ant.project.name} 
        setting manifest debug state to true</echo>
</target>

<target name="-set-release-mode" depends="-set-mode-check">
......
    <property name="match.start" value="android:debuggable="/>
    <property name="match.end" value=">"/>
    <replaceregexp file="AndroidManifest.xml"
               match="${match.start}.*${match.end}"
               replace="${match.start}&quot;false&quot;${match.end}">
    </replaceregexp>

    <echo level="info">${ant.project.name} 
         setting manifest debug state to false</echo>

</target>

Then in code I placed in my custom Application class I created a static I can reference in my activities.

DEBUG = (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;

Then when I need to hide/show stuff I use:

if (MyApplication.DEBUGGABLE) {
    ...show stuff
} else {
    ...hide stuff
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top