Reputation: 5246
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.
Upvotes: 2
Views: 6849
Reputation: 3783
Answering a bit late but this is what I did.
First create manifest variables in Gradle as so:
buildTypes {
debug {
manifestPlaceholders = [ applicationLabel: "@string/app_name_dev",
azureRedirectURI: "URI_FOR_DEV"]
}
release {
manifestPlaceholders = [ applicationLabel: "@string/app_name",
azureRedirectURI: "URI_FOR_PROD"]
}
}
And then in the manifest you can do this:
<application android:label="${applicationLabel}" />
<activity android:name="com.microsoft.identity.client.BrowserTabActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!--Add in your scheme/host from registered redirect URI-->
<data
android:scheme="${azureRedirectURI}"
android:host="auth" />
</intent-filter>
</activity>
Upvotes: 5
Reputation: 1007266
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.
Upvotes: 6