I have an application that only have Services, Receivers and Activities that are not directly accessed by the use (there is no launcher activity).
But now I have to add an activity to be used as launcher activity BUT this launcher activity must be present only when the app has some specific variables set during the BUILD.
So basically, when calling the gradle build I set a variable HAS_LAUNCHER=1
and in my build.gradle I have something like:
defaultConfig {
...
def hasLauncher = System.getenv("HAS_LAUNCHER")
if (hasLauncher != null && hasLauncher == "1") {
// Something here to include the activity tag in the AndroidManifest.xml
}
}
And in my AndroidManifest I have to add the <activity>
tag when that if
condition is true:
<activity
android:name=".LauncherActivity"
android:label="Launcher"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
How can I accomplish that without using a new dimension of productFlavors? (the app already has a dimension with 3 flavors and 2 buildTypes, so I don't want to make even more outputs)
may be too late, but after many days searching for a solution I have done in this way :
gradle defaultConfig
In the builTypes
In manifest
This way you can control activity visibility from gradle. Note that you can also use in code , just create a bool resource showActivity , it will be replaced by gradle value and you'll be able to read it