Android duplicate provider authority problem
android, android-contentprovider, google-play
Solution
Basically what I did is, create an abstract base class for each of my ContentProviders and inherit from that for each app I want to make, overriding the authority path. So in my AbstractContentProvider I have:
public AbstractContentProvider() {
sURIMatcher.addURI(getAuthority(), BASE_PATH, ITEMS);
sURIMatcher.addURI(getAuthority(), BASE_PATH + "/#", ITEM_ID);
}
protected abstract String getAuthority();
and then in each subclass I have:
private static final String AUTHORITY = "my.package.app1.ContentProvider";
@Override
protected String getAuthority() {
return AUTHORITY;
}
In the AndroidManifest I register these with:
<provider
android:name="my.package.app1.ContentProvider"
android:authorities="my.package.app1.ContentProvider">
</provider>
Now the trick is, I want to access these content providers in common (library) code, that doesn't know about the app specific classes. To do that, I define a String in my strings.xml, that I override for each app. Then I can use:
Uri.parse(getString(R.string.contentProviderUri))
and in every app the right ContentProvider is used without any conflicts. So basically using the configuration mechanism for dependency injection.
Problem
We're trying to publish a pay ad-free version of a casual app that's currently published free with ads. We refactored all package names to `com.mycompanyname.appname.pro`, the free one on market doesn't have the .pro at the end, basically. We also went into our content provider and changed the authority to the same as the package name. So the "free version" has ``` AUTHORITY = "com.mycompanyname.appname" ``` and the "ad-free pay version has ``` AUTHORITY = "com.mycompanyname.appname.pro" ``` but still we are unable to install both the free and the "pro" version on the same device. For whatever it's worth, the class name for the provider is the same in both apps. We can't install from an apk directly, and if we try to download from Android market we get a "duplicate provider authority" error message. What are we missing? Is there another place we need to look for problems, or have we got something fundamentally wrong here?