react-native-image-crop-picker icon indicating copy to clipboard operation
react-native-image-crop-picker copied to clipboard

Error: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference

Open iam-febriansyah opened this issue 7 years ago • 16 comments
trafficstars

Version

"react-native": "^0.52.0", "react-native-image-crop-picker": "^0.19.1",

Platform

  • Android

Manifest.xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

gradel dependencies { classpath 'com.android.tools.build:gradle:2.2.3' }

distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.zip

iam-febriansyah avatar Feb 01 '18 06:02 iam-febriansyah

its same issue if use distributionUrl=https://services.gradle.org/distributions/gradle-2.14.1-all.zip

iam-febriansyah avatar Feb 01 '18 07:02 iam-febriansyah

Same issue here after upgrading React Native. Did you find a workaround / solution @riansyaaah?

alexcouret avatar Feb 12 '18 20:02 alexcouret

@OzoTek i create new project React Native and move my script on old project to new project. That bad solution but its work for me

iam-febriansyah avatar Feb 13 '18 04:02 iam-febriansyah

add this to your AndroidManifest.xml file

<provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths" />
        </provider>

and add this to your android/app/main/res/xml/provider_paths.xml

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_files" path="."/>
</paths>

drmas avatar Feb 26 '18 18:02 drmas

I tried once more and finally got it work

  1. add this to your AndroidManifest.xml file (between the <application> and </application> tags)
<provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths" />
        </provider>
  1. and add this to your android/app/main/res/xml/provider_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_files" path="."/>
</paths>

hycwong avatar Feb 27 '18 16:02 hycwong

I used the above's code, but still have a error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute provider#android.support.v4.content.FileProvider@authorities value=(com.xxx.provider) from AndroidManifest.xml:39:13
  	is also present at Select:react-native-image-crop-picker:unspecified:15:13 value=(com.reactnative.ivpusic.imagepicker.provider)
  	Suggestion: add 'tools:replace="android:authorities"' to <provider> element at AndroidManifest.xml:37:7 to override

So you need add tools:replace="android:authorities" into <provider> tag like this:

<provider
    tools:replace="android:authorities"
    android:name="android.support.v4.content.FileProvider"
    android:authorities="${applicationId}.provider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/provider_paths" />
</provider>

and add the name space for tools:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    ...
    >

WosLovesLife avatar Mar 02 '18 05:03 WosLovesLife

I'm still getting the same behaviour using this solution

alexcouret avatar Mar 02 '18 20:03 alexcouret

same here. Image is saved here: file:///data/user/0/com.mypet/cache/ReactNative-snapshot-image-164856113.jpg

The path attribute shares the images/ subdirectory of files/. The name attribute tells the FileProvider to add the path segment myimages to content URIs for files in the files/images/ subdirectory. https://developer.android.com/training/secure-file-sharing/setup-sharing.html

this confuse me in the documentation

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <cache-path path="com.mypet/" name="cache" />
</paths>

filepaths.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.mypet">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize">
        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="com.mypet.fileprovider"
            android:grantUriPermissions="true"
            android:exported="false"
            tools:replace="android:authorities">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths" />
        </provider>
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>

</manifest>

AndroidManifest.xml

https://developer.android.com/reference/android/support/v4/content/FileProvider.html#SpecifyFiles

nu5rim3 avatar Mar 16 '18 06:03 nu5rim3

same issue

alihesari avatar May 01 '18 21:05 alihesari

same issue

Yibay avatar Jun 29 '18 05:06 Yibay

Finally solved it..

In my case Suggestion: add 'tools:replace="android:resource"' to element at AndroidManifest.xml:37:7 to override

<provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:grantUriPermissions="true"
            android:exported="false">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths"
                tools:replace="android:resource"/> // add this line.
        </provider>

ZeroCool00 avatar Jul 13 '18 12:07 ZeroCool00

+1

oferRounds avatar Aug 21 '18 05:08 oferRounds

same issue

Jeijie avatar Nov 07 '18 05:11 Jeijie

In my case it gives error on the camera plugin, so I change the xml value of the meta-data in provider to camera_provider_paths. Snippet as below:

<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/camera_provider_paths" /> </provider>

If you don't want to edit AndroidManifest.xml everytime you rebuilt, you may edit the config.xml with snippet below:

<config-file parent="./application" target="AndroidManifest.xml"> <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/camera_provider_paths" /> </provider>

vicheanak avatar Dec 17 '18 10:12 vicheanak

If you've migrated over to react >0.60, make sure you use androidx.core.content.FileProvider instead if android.support.v4.content.FileProvider causes crashes when you boot up your app.

iJimmyWei avatar Aug 07 '19 09:08 iJimmyWei

tools:replace="android:authorities"

this solved my problem. Thanks!!!

navalcode avatar May 19 '22 10:05 navalcode