Android library projects and applicationid

2,462 views
Skip to first unread message

Kevin Kovach

unread,
Dec 3, 2014, 10:05:36 PM12/3/14
to adt...@googlegroups.com
I see in the release notes for version 1.0.0-rc1 of the gradle plugin that "Setting applicationId(Suffix) in a Library project will now properly fail.", but I do not see anything indicating an alternative. How are we supposed to be setting the package name in library projects? Thanks.

- Kevin

Xavier Ducrohet

unread,
Dec 3, 2014, 11:58:53 PM12/3/14
to adt...@googlegroups.com
A library package can only have the package name declared in its manifest. It's a limitation due to how the R class of the library is not packaged in its classes.jar and instead created by the consuming app.

Since the consuming app uses the library's manifest's package to generate the R class there's no way in the library to have a different package name for different variants (since in an app project, all variants use the original manifest package name for the R class and overrides the package name only in the packaged manifest) 

If you need to provide different libraries with different packages, you should use different modules.

On Wed, Dec 3, 2014 at 7:05 PM, Kevin Kovach <kov...@gmail.com> wrote:
I see in the release notes for version 1.0.0-rc1 of the gradle plugin that "Setting applicationId(Suffix) in a Library project will now properly fail.", but I do not see anything indicating an alternative. How are we supposed to be setting the package name in library projects? Thanks.

- Kevin

--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

Imran Mohammed

unread,
Feb 23, 2015, 10:29:01 AM2/23/15
to adt...@googlegroups.com
How can I get the applicationId of the application in a library?

context.getPackageName() will give the right applicationId.
I need to set the authority of a content provider to match with the applications Id of the application.

Thanks.
Imran

Jerome Dochez

unread,
Feb 23, 2015, 7:23:17 PM2/23/15
to adt...@googlegroups.com
The easiest is to define a placeholder called "mainApplicationId" and do not set it when building the library. The placeholder will remain unchanged since there is no value provided. Once you build the application, set the placeholder to a the applicationId and it will be replaced in the resulting merged AndroidManifest.xml

We might look into not providing an automatic "applicationId" binding when building library in the future which will allow you to just use ${applicationId} everywhere but it's not implemented yet.

Jerome

Pascal Welsch

unread,
Mar 31, 2015, 6:59:57 PM3/31/15
to adt...@googlegroups.com
I have the same problem Imran described. My ContentProvider in the library depends on the applicationId of the product flavor

Streets Of Boston

unread,
Apr 1, 2015, 11:16:48 AM4/1/15
to adt...@googlegroups.com
Put the value of your ContentProvider authority in a resource-string. In your library, give it an empty or dummy value.j
In the app that uses your library, redefine that resource-string with proper value.
Reply all
Reply to author
Forward
0 new messages