Reputation: 36
I am creating an Android library that uses SyncAdapter to do a small task in the background every day. This works perfectly fine if used in only one app. If the same library is used by two apps in the same phone, it gives CONFLICTING_PROVIDER
error.
To fix this. I used ${applicationId}
in library manifest like:
<provider
android:name=".sync.DummyProvider"
android:authorities="${applicationId}.mysdk"
android:exported="false"
android:syncable="true" />
This generates dynamic authority for the provider.
Now, the problem is that SyncAdapter needs to have contentAuthority
in the xml folder.
<sync-adapter
xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="@string/sync_account_type"
android:allowParallelSyncs="false"
android:contentAuthority="<-----NOT SURE WHAT TO ADD HERE----->"
android:isAlwaysSyncable="true"
android:supportsUploading="false"
android:userVisible="false"/>
I tried android:contentAuthority="${applicationId}.mysdk"
but applicationId doesn't get replaced by the app's package name. Instead, it take it as it is and gives error as:
E/ActivityThread: Failed to find provider info for ${applicationId}.mysdk
These are the step I have tried till now
Upvotes: 1
Views: 206
Reputation: 36
@pranav-agraval's answer worked.
I didn't change anything in the SDK. The string resource I was using had a key content_provider
.
I would have to ask any one who is using the SDK to add this key to their string.xml
file. This should be of pattern application_package_name.sdk_name
.
Upvotes: 0
Reputation: 1268
First you need to declare the application id in your build.gradle file
defaultConfig {
applicationId "com.my.package"
....
}
Then use the following xml for your syncAdapter
<sync-adapter
xmlns:android="http://schemas.android.com/apk/res/android"
android:contentAuthority="@string/account_authorities"
android:accountType="@string/account_type"
android:userVisible="false"
android:supportsUploading="false"
android:allowParallelSyncs="false"
android:isAlwaysSyncable="true"/>
Upvotes: 1