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
- Creating stringValue from build.gradle in library's build.gradle file, but here applicationId can not be used there.
- Moved contentAuthority in the Manifest, as ${applicationId} works there but nothing happens after doing this. contentAuthority needs to be in the xml folder.