Blog Infos
Author
Published
Topics
,
Published

In this article, you will learn how to make use of Android Manifest placeholders to supercharge your Android app development.

Injecting Variables into AndroidManifest.xml
// build.gradle
android {
  defaultConfig {
    manifestPlaceholders.baseUrl = "api.demoserver.com"
  }
}

Here, the variable name is baseUrl whereas the assigned string is the value which will be received by AndroidManifest.xml once declared as below:

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

Similarly, other examples can include properties such as applicationId, screenOrientation as well as frequently used elements in the AndroidManifest.xml:

// build.gradle
android {
  defaultConfig {
    applicationId "example.manifest.app"
  }
  buildTypes {
    release {
      manifestPlaceholders.screenOrientation = "portrait"
    }
    debug {
      manifestPlaceholders.screenOrientation = "unspecified"
    }
  }
}

Which can be used in your Manifest as below:

// AndroidManifest.xml
<intent-filter ... >
  <action android:name="${applicationId}" />
</intent-filter>
<uses-sdk tools:overrideLibrary="${applicationId}.home, ${applicationId}.util" />
<activity
  android:name=".MainActivity"
  android:screenOrientation="${screenOrientation}" />

Alternatively, you can specify in the form of key-value pairs at once by assigning manifestPlaceholders as array like this:

// build.gradle
android {
  defaultConfig {
    manifestPlaceholders = [baseUrl: "dev.demoserver.com",
                            screenOrientation: "portrait",
                           ]
  }
}
Managing Multiple Manifests
// build.gradle
android {
  buildTypes {
    release { ... }
    debug { ... }
  }
  flavorDimensions "ui", "paidui", "trialui", "referralui"
  productFlavors {
    paid {
      dimension "ui"
    }
    free {
      dimension "paidui"
    }
    trial {
      dimension "trialui"
    }
    referral {
      dimension "referralui"
    }
  }
}
Merging Multiple Manifests
Merge
Merge Children Only
Keep
Manifest Merge Conflicts and Resolution
Build Your Own Manifest
Support Multiple Deep Links
<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.BROWSABLE"/>
  <category android:name="android.intent.category.DEFAULT" />
  <!-- custom intent filter definition for deep links -->
  ${deepLinks_manifestPlaceholder}
</intent-filter>

 

Job Offers

Job Offers


    Senior Android Software Engineer (f/m/d)

    Paradox Cat GmbH
    Munich
    • Full Time
    apply now

    Android Software Engineer (f/m/d)

    Paradox Cat GmbH
    Munich
    • Full Time
    apply now

    Mobile Engineer

    OLX Group
    Remote, Portugal, Spain, Romania, Poland
    • Full Time
    apply now

OUR VIDEO RECOMMENDATION

,

Plugging Into the Gradle Matrix

Whether consolidating build script logic, writing convention plugins, or adding tooling to your apps, Gradle plugins are powerful ways to extend your build.
Watch Video

Plugging Into the Gradle Matrix

John Rodriguez & Tony Robalik
Android engineer & Senior software person
Android & Square

Plugging Into the Gradle Matrix

John Rodriguez & T ...
Android engineer & ...
Android & Square

Plugging Into the Gradle Matrix

John Rodriguez & ...
Android engineer & Senio ...
Android & Square

Jobs

Manage Your Sentry.io Configuration
<application>
  <meta-data android:name="io.sentry.dsn" android:value="https://1093t8yhqfw8h819@x11.ingest.sentry.io/123123" />
  <!-- Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
   We recommend adjusting this value in production. -->
  <meta-data android:name="io.sentry.traces.sample-rate" android:value="1.0" />
</application>
<meta-data android:name="io.sentry.traces.activity.enable" android:value="true" />
<meta-data android:name="io.sentry.traces.activity.auto-finish.enable" android:value="true" />
android {
  buildTypes {
    release { 
      manifestPlaceholders.sentryTraceSampleRate = "0.6"
      manifestPlaceholders.sentryActivityTrace = true
      manifestPlaceholders.sentryAutoFinishActivityTrace = true
    }
    debug {
      manifestPlaceholders.sentryTraceSampleRate = "1.0"
      manifestPlaceholders.sentryActivityTrace = false
      manifestPlaceholders.sentryAutoFinishActivityTrace = false
    }
  }
}

With the above build.gradle, you can modify your AndroidManifest.xml to support placeholders as below:

// AndroidManifest.xml
<application>
  <meta-data android:name="io.sentry.dsn" android:value="https://1093t8yhqfw8h819@x11.ingest.sentry.io/123123" />
  <!-- Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
      We recommend adjusting this value in production. -->
  <meta-data android:name="io.sentry.traces.sample-rate" android:value="${sentryTraceSampleRate}" />
  <meta-data android:name="io.sentry.traces.activity.enable" android:value="${sentryActivityTrace}" />
  <meta-data android:name="io.sentry.traces.activity.auto-finish.enable" android:value="${sentryAutoFinishActivityTrace}" />
</application>
Conclusion

YOU MAY BE INTERESTED IN

YOU MAY BE INTERESTED IN

blog
Managing dependencies in a single module project is pretty simple, but when you start…
READ MORE
blog

Running Instrumented Tests in a Gradle task

During the latest Google I/O, a lot of great new technologies were shown. The…
READ MORE
blog
Mobile device concept is one step ahead of the trend in technology, bringing an…
READ MORE
blog
According to the Gradle documentation dependency resolution is a process that consists of two…
READ MORE

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Menu