Search code examples
androidandroid-studiomergeandroid-manifestplaceholder

Android Studio: Is it possible to define library module manifest placeholders in main module?


I'm adding some components to a library module manifest file. Apparently it is possible to use the ${applicationId} placeholder even though I have not declared it in the library's build.gradle file. The only place it is declared is in the main module's build.gradle.

So I though if I added a custom placeholder to the main module it would also work.

In short: this seems to work:

Library's AndroidManifest.xml:

<activity android:name="${applicationId}.LibraryActivity" ...>

Main module's build.gradle:

defaultConfig {applicationId "package.name.here"...


But this does not:

Library's AndroidManifest.xml:

<activity android:label="${customPlaceholder} ...>

Main module's build.gradle:

defaultConfig {manifestPlaceholders = [customPlaceholder:"Foo"] ...}


Is there a reason one works but not the other?


Solution

  • Yes! We can do it!

    Just add the code to library's build.gradle:

        manifestPlaceholders = [
                customPlaceholder: '${customPlaceholder}'
        ]
    

    Or in build.gradle.kts:

    manifestPlaceholders["customPlaceholder"] = "\${customPlaceholder}"