I am developing a set of apps that are distinguished only in certain brandings (think different sports teams); however, I am running into a problem where I am using one Library project for all of the specifically branded apps and want to use the same ContentProvider for all of them. When I created the ContentProvider I declared the AUTHORITY as a constant in the class (per the dev example code) and I am using the same authority in every specific app in the manifest files. It looks like I can't use the same authority across every app as I get this error when trying to install a second app (I install one branded one just fine but the second install):
WARN/PackageManager(66): Can't install because provider name com.xxx.Provider (in package com.xxx) is already used by com.zzz
I've tried several approaches but none of them seem to work. One idea that I haven't done yet, was to create a library jar and just omit the Provider class I have and customize it in each specific app. Any ideas on how to get around this problem without resorting to that?
It's an old question, but I was looking at doing something similar recently. With the Build flavours, its really straight forward now.
Specify the BuildConfigField in the gradle file:
productFlavors {
free {
applicationId "com.example.free"
buildConfigField 'String', 'AUTHORITY', '"com.example.free.contentprovider"'
}
paid {
applicationId "com.example.paid"
buildConfigField 'String', 'AUTHORITY', '"com.example.paid.contentprovider"'
}
Specify the provider authority in the manifest:
<provider
android:name=".ContentProvider"
android:authorities="${applicationId}.contentprovider" />
Set the authority in the provider using the BuildConfigField Variable:
public static final String AUTHORITY = BuildConfig.AUTHORITY