React-native-image-crop-picker: cannot openCamera in android

Created on 15 Dec 2016  ·  21Comments  ·  Source: ivpusic/react-native-image-crop-picker

Version
"react": "15.3.2",
"react-native": "0.37.0",
"react-native-image-crop-picker": "^0.10.5",
"gradle" :v2.4

Platform
Android (荣耀8 FRD-AL10 android: 6.0)

Error
when I call ImagePicker.openCamera , error appears:

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(…)

Most helpful comment

check android/app/src/main/AndroidManifest.xml

if not exists, add < uses-permission android:name="android.permission.CAMERA" />

All 21 comments

can you please provide more details, like stacktrace? Thanks

@pvsong can you provide stacktrace?

check android/app/src/main/AndroidManifest.xml

if not exists, add < uses-permission android:name="android.permission.CAMERA" />

@ivpusic I have same problem,
Version
"react": "15.3.1",
"react-native": "0.38.0",
"react-native-image-crop-picker": "^0.10.9",
"gradle" :v2.2

Platform
Android (Redmi 3 android: 5.11 and Galaxy Note3 SM-N9008v android: 5.0 and HUAWEI P8 android: 5.11)
I alst add : < uses-permission android:name="android.permission.CAMERA" />

I already can use openCamera when update gradle version 1.2.3 to 2.2.2.
image

Same problem! @ivpusic any fix? i'm running RN 0.33 on actual device

@ivpusic upgrate "react-native-image-crop-picker": "^0.11.2", I have this same problem

@ivpusic Any update? Any way I can help you solve this issue?

@ethan37 problem is that I cannot reproduce this issue. Could you please try running example android project. When example application starts, there will be button to open camera. Could you please check if error happens there as well? Thanks

@ivpusic I've finally found a solution! :+1:

The issue lies in the gradle version your app is using. After switching to gradle 2.2.2 and making sure that distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip is in gradle/wrapper/gradle-wrapper.properties everything works fine.

Shouldn't this gradle thing be specified somewhere in the docs?

@sunny20131314 @iamdurui @pvsong can you try the above solution to check if it works for you too, if you still haven't fixed this issue? :)

@ethan37 thanks,but I have a problem, I try your solution,the phone (HUAWEI P8 android: 5.11) don't install the apk ,I find the solution ,it's switching to gradle 1.2.3, Do you have solution?

@iamdurui same... the only solution is using gradle 1.2.3 for development and gradle 2.2.2 for production.

Edit. I mean use the simulator with gradle 2.2.2 when you need to use react-native-image-crop-picker... if you don't need to use it switch to gradle 1.2.3 with physical device. For production/release use gradle 2.2.2

@ethan37 thanks! this is a good idea!

@ivpusic can we upload any file type in Android (For ex-pdf, text, doc etc) currently when I try to upload pdf file it gives error "Invalid image selected" in Android.
Can you please provide any solution regarding that.

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>

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"
    ...
    >

Hi, I don't want to open a new issue, but I have a problem with permissions on Android.
I added all the necessary boilerplate, including the provider code and file, but I am using gradle 3.01 , maybe that's an issue? I am not expert and I am not sure.

My problem is that when the Alert asking for permssion shows up and I click "OK" to grant the permission, I receive this error in the callback:
Error: Required permission missing at createErrorFromErrorData (NativeModules.js:123) at NativeModules.js:80 at MessageQueue.__invokeCallback (MessageQueue.js:346) at MessageQueue.js:132 at MessageQueue.__guard (MessageQueue.js:262) at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:131) at debuggerWorker.js:72

It says that I am missing a permission, but it should add it when I clicked "OK", shouldn't it? Anyone had the same problem ?

same issue

Same issue as @Karniej
Gradle version:3.1.2
react-native-image-crop-picker": "0.20.1
In menifest storage and camera permission is added

I also added all permission and followed the npm manual very well still getting error ==>

Error in camera picker ==> Error: Required permission missing
at Object.fn [as openCamera] (NativeModules.js:99)
at ImageCropPicker.cameraPicker (index.js:57)
at ImageCropPicker._this.handlePickerSelection (index.js:35)
at Object.onPress (index.js:22)
at Object.touchableHandlePress (TouchableOpacity.js:264)
at Object._performSideEffectsForTransition (Touchable.js:880)
at Object._receiveSignal (Touchable.js:779)
at Object.touchableHandleResponderRelease (Touchable.js:490)
at Object.invokeGuardedCallbackImpl (ReactNativeRenderer-dev.js:307)
at invokeGuardedCallback (ReactNativeRenderer-dev.js:531)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Martian2Lee picture Martian2Lee  ·  3Comments

zhangjunhou picture zhangjunhou  ·  3Comments

Phenek picture Phenek  ·  3Comments

JodiWarren picture JodiWarren  ·  3Comments

phantom1299 picture phantom1299  ·  3Comments