Skip to content

Most visited

Recently visited

navigation

Inject Build Variables into the Manifest

If you need to insert variables into your AndroidManifest.xml file that are defined in your build.gradle file, you can do so with the manifestPlaceholders property. This property takes a map of key-value pairs, as shown here:

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

You can then insert one of the placeholders into the manifest file as an attribute value like this:

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

By default, the build tools also provide your app's application ID in the ${applicationId} placeholder. The value always matches the final application ID for the current build (including changes by build variants. This is useful when you want to use a unique namespace for identifiers such as an intent action, even between your build variants.

For example, if your build.gradle file looks like this:

android {
    defaultConfig {
        applicationId "com.example.myapp"
    }
    productFlavors {
        free {
            applicationIdSuffix ".free"
        }
        pro {
            applicationIdSuffix ".pro"
        }
    }
}

Then you can insert the application ID in your manifest like this:

<intent-filter ... >
    <action android:name="${applicationId}.TRANSMOGRIFY" />
    ...
</intent-filter>

And the manifest result when you build the "free" product flavor is this:

<intent-filter ... >
   <action android:name="com.example.myapp.free.TRANSMOGRIFY" />
    ...
</intent-filter>

For more information, read Set the Application ID.

This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.