1

I need a way to assign different Shared User ID(during installation) to the same Android App(same APK) based on the device model during installation. I couldn't find any documentation about conditional statements being supported in the manifest file. Any help would be greatly appreciated.

iHavADoubt
  • 79
  • 1
  • 9
  • Use product flavors. You can start here http://stackoverflow.com/questions/28478110/android-studio-two-flavors-with-different-manifest-files (slightly different question, but gives you basic understanding). – skywall Jul 16 '15 at 07:26
  • I can have only one APK. So, this needs to happen at run time, not at compile time. – iHavADoubt Jul 16 '15 at 07:29
  • 1
    I don't think that setting Shared User ID is allowed in runtime. I think that this is impossible or forbidden due to security reasons. – Pawel Urban Jul 16 '15 at 07:33
  • Sorry, I think I was not clear. I meant that this is not a build time feature. It needs to be install time (assigning shared user id during installation is definitely supported). I only need a way to use conditional statements in the manifest. – iHavADoubt Jul 16 '15 at 07:38

2 Answers2

1

Though this is a pretty old question, but I stumbled upon a similar problem recently and this might help someone who's still searching for a solution. My case was that I had to assign some key in AndroidManifest.xml at runtime based on a condition. While I couldn't find a way to define conditions in Manifest, I was able to pass the way to Manifest from build.gradle. If the condition can be checked in build.gradle, then you can pass value to Manifest in the following way

android {
    defaultConfig {
        manifestPlaceholders = [hostName:"www.example.com"]
    }
    ...
}

And then access it in Manifest as -

<intent-filter ... >
    <data android:scheme="https" android:host="${hostName}" ... />
    ...
</intent-filter>

Documentation - https://developer.android.com/studio/build/manifest-build-variables Furthermore, you can generate strings, bool and other values from build.gradle which can then be used app-wide.

buildConfigField "int", "FOO", "42"
resValue "string", "app_name", "My App Name Debug"
0

The closest you can get to conditionality in the manifest is to not include a value as a constant, but rather use a redirect to the resources. You then provide different resources for different languages, devices etc.

The documentation for the manifest element states that the Shared User id should be a string, but for example the Shared User label must be a string resource (since you would typically need to translate it). Whether you can get away with making the id a resource as well is hard to guess - the documentation is often inaccurate about this, but be aware that what works on one version of Android may not be true for all versions.

zmarties
  • 4,809
  • 22
  • 39