Ionic build failed "unexpected element <provider> found in <manifest>"

Viewed 2589

I have this code

<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="nl.x-services.plugins.videocaptureplus.provider"
    android:exported="false"
    android:grantUriPermissions="true" >
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/provider_paths" />
</provider>

But if i try "Ionic cordova run android" i have this error

https://pastebin.com/BAtL0VqK

What can I do with this error?

6 Answers

The issue seems to be with VideoCapturePlus as I was getting the same problem. I have swapped it for MediaCapture and no longer have this problem.

There is indeed a <provider> element wrongly injected in the resulting AndroidManifest.xml.
This element comes from the plugin.xml file of the videoCapturePlus plugin.

  1. comment out the faulty lines in file /node_modules/cordova-plugin-video-capture-plus/plugin.xml

         <provider
                 android:name="android.support.v4.content.FileProvider"
                 android:authorities="nl.x-services.plugins.videocaptureplus.provider"
                 android:exported="false"
                 android:grantUriPermissions="true">
             <meta-data
                     android:name="android.support.FILE_PROVIDER_PATHS"
                     android:resource="@xml/provider_paths"/>
         </provider>
    
  2. re-generate the platform files (android) using command-line

ionic cordoba build android or ionic capacitor build android

  1. re-run the gradle build in android studio

That's it !

Try to remove this code from plugin/nl.x-services.plugins.videocaptureplus/plugin.xml

I fix editing platform/android/android.json

move the block

step 1 into "Application" block step 2

This is the sequence I did

npx cordova platform rm android --nosave
npx ionic cordova plugin rm nl.x-services.plugins.videocaptureplus
npx ionic cordova plugin add https://github.com/Neocrea/cordova-plugin-video-capture-plus\#patch-1
npx ionic cordova platform add android@latest

I used https://github.com/Neocrea/cordova-plugin-video-capture-plus\#patch-1 because it had the requisite patch that fixes the issue. It's not the best solution IMO, instead you should be using media capture plugin instead which is something we are migrating to, but this is a stop gap.

I have fixed this issue and working perfectly in my case on android, just follow the steps:

  1. In file platforms\android\android.json
  2. Remove below code inside array "AndroidManifest.xml": { "parents": { "/manifest/application": [ "/*": [ .... ]

{ "xml": "<provider android:authorities="nl.x-services.plugins.videocaptureplus.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" />", "count": 1 }

  1. And put the code in "application" array

enter image description here

and make build again : ionic cordoba build android (Command line) and in android studio, re-run the gradle build

Related