Search code examples
androidantandroid-manifest

Conditionals in Android Manifest?


Is it at all possible to have conditionals in the Android Manifest? I know that straight out of the box it probably isn't, as this is relied upon by R.java etc. What I'm hoping for is some plugin that'll replace certain parts (comment/uncomment also) of the manifest to simplify my deployment process.

Basically, we've got some devices that we want to lock down completely, so I set them as category.HOME etc. But we also still have some personal devices we still use for testing. As such, it's quite tedious ensuring that I'm not blatting personal devices with a new launcher.

It's petty I know, but in previous languages I'd use ifdef etc, but Java doesn't work this way.

I've managed to find this: http://www.ibm.com/developerworks/rational/library/09/eclipsecustomanttasks/ - Which, given some time I could possibly fudge something together, but I must admit, I don't really know where to start, or even if this would be possible?

Was hoping that someone had thought of this before and had a magic solution! :)

Cheers.


Solution

  • You can have a boolean resource -- call it is_this_for_realz here -- that is set to true for production and false otherwise. You can then set up an <activity-alias> that has your HOME <intent-filter>, where that <activity-alias> has android:enabled="@bool/is_this_for_realz". Then, whether that HOME filter will be used depends upon the state of that boolean resource. You would need to arrange to have your production builds swap in a resource file that sets is_this_for_realz to true, whereas your normal debug builds would have it be false.

    As Machinarius notes, this becomes much simpler with Gradle for Android. You can go with the boolean resource approach, but have the debug/release variations of is_this_for_realz be driven by Gradle build type. Or you can have different manifests for debug and release, if you encounter problems with the <activity-alias> technique.