Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error with duplicated FileProvider in manifest.xml with Cordova

How is it possible to have multiple provider of the same type in the manifest? Since the cordova camera plugins brings a file provider, our app can't be build anymore. In the manifest we have the following:

<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 comes from the camera plugin, the second from one of our plugins.

During build, the following error occurres:

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

Thanks!

like image 614
Robert Avatar asked Nov 22 '16 15:11

Robert


1 Answers

I think this is not a cordova problem but inside the android build process. At least i could reproduce it within a plain Android Studio and Gradle setup:

It seems that android is not OK with having two tags with the same name attribute. I don't see why this is a problem as long as you have different authorities it should work fine. But this also leads to a solution:

within YOUR plugin (or your own fork of the plugin you want to use). You create your own FileProvider.java which just extends the original android.support.v4.content.FileProvider

package com.our.app.dev;

public class FileProvider extends android.support.v4.content.FileProvider {
} 

within your plugin configuration you link to this FileProvider, which now has a different package name, thus avoiding this problem. Hope this works, for me it seems to do the trick.

like image 92
r-hold Avatar answered Oct 14 '22 10:10

r-hold