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

1

17

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?

Misleading answered 2/2, 2016 at 10:7 Comment(2)
Did you find some way to achieve this? I have the same scenario as yours.Kindness
I have something similar but not exactly the same. My library module is having a Launcher activity which I want to replace with the one in the Main app's Manifest. Is there a way to manage that as well? I can't edit the Main app as it has different vendor. I am just a module which it uses as a dependency. Manifest Merger doesn't work as Lib has lower priority.Underwent
I
16

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}"
Itinerancy answered 21/9, 2017 at 1:55 Comment(5)
Make sure you use '${customPlaceholder}' instead of "${customPlaceholder}" took me 1hCronk
If using build.gradle.kts it is: manifestPlaceholders["customPlaceholder"] = "\${customPlaceholder}"Harlequin
I'm a bit confused by this answer. The value is surrounded by single quotes and it was my understanding that single quotes should only be used for direct strings, right? I get the impression this 'works' for the wrong reasons.Opposable
The correct way is using double quote.Landa
@ClausHolst Thanks for the info, this was so hard to find lolSinistrous

© 2022 - 2024 — McMap. All rights reserved.