Android – error using duplicate fileprovider in manifest.xml with Cordova
How is it possible to have multiple providers of the same type in the list? Due to the file provider brought by Cordova camera plug-in, our application can no longer be built. In the list, we have the following contents:
<provider android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider">
<Meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/>
</provider>
<provider android:authorities="com.our.app.dev.fileprovider" android:exported="false" android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider">
<Meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_provider_paths"/>
</provider>
The first entry is from the camera plugin, and the second one is from one of our plugins
During the build process, the following errors occur:
AndroidManifest.xml:44:5-46:16 Error:
Element provider#android.support.v4.content.FileProvider at AndroidManifest.xml:44:5-46:16 duplicated with element declared at AndroidManifest.xml:41:5-43:16
thank you!
resolvent:
I don't think this is a Cordova problem, but in the process of Android construction. At least I can reproduce it in simple Android studio and gradle settings:
It seems that Android cannot have two tags with the same name attribute. I don't understand why this is a problem. As long as you have different permissions, it should work normally. But this also leads to a solution:
In your plug-in (or your own branch of the plug-in you want to use), you create your own fileprovider.java, which only extends the original android.support.v4.content.fileprovider
package com.our.app.dev;
public class FileProvider extends android.support.v4.content.FileProvider {
}
In your plug-in configuration, you link to this fileprovider, which now has different package names to avoid this problem. I hope this is useful and seems to solve the problem for me