ivpusic / react-native-image-crop-picker

iOS/Android image picker with support for camera, video, configurable compression, multiple images and cropping
MIT License
6.14k stars 1.56k forks source link

App crashes on Android (openPicker and openCamera) #613

Open alexcouret opened 6 years ago

alexcouret commented 6 years ago

Version

Tell us which versions you are using:

Platform

Tell us to which platform this issue is related

Expected behaviour

openCamera: Open camera openPicker: Select a picture in the gallery

Actual behaviour

openCamera: Crashes while opening (E_FAILED_TO_OPEN_CAMERA) openPicker: Crashes after selecting a picture (no logs, not even entering in a catch)

Permissions are all given.

Steps to reproduce

openCamera: ImagePicker.openCamera({width: 1000, height: 1000, cropping: true})

openPicker: ImagePicker.openPicker({width: 1000, height: 1000, cropping: true}) then select a picture

Attachments

openCamera:

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

I was just upgrading my packages, and it also happens that my phone was upgraded from Android 7.x to 8.0, so I'm not sure whether it's because of the new version of Android or React / React Native. Seems to be working fine on iOS though.

EDIT: Just tested on Android 7.1.1, I get the exact same behaviour.

ivpusic commented 6 years ago

do you have some time to debug this? I cannot reproduce it

alexcouret commented 6 years ago

Not really but I'll try to understand what's going on, must be on my side then

profiVideos commented 6 years ago

It definitely seems to be an Android 8.0 problem. I have the same code 0.19.1 running fine on various Android 7.1.1 emulators. As soon as I try it on Android 8.0, just as OzoTek mentioned, it crashes hard when selecting a photo from the gallery. I've been testing on Android 7 and just today tried it on 8. Using RN 0.51 BTW.

drmas commented 6 years ago

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>
profiVideos commented 6 years ago

Hi Guys, tried this out today. A small typo in the second add from above should read; android/app/src/main/res/xml/provider_paths.xml

However, sadly this fix has NOT worked for me. Same behavior as before. Select an image for cropping from the gllery or where ever and program crashes SEVERELY - no error message, nothing.

Cheers, Markus

profiVideos commented 6 years ago

Hi guys, is anyone else here using this module with Android? I'm getting close to releasing my App (free app unless you want cloud services) on Google PlayStore. As it stands now, I cannot release if I know that a large portion of users running on Android 8 will not be able to use the app.

I'm attaching some animated gifs of the App working fine on Android 7.1.1 (Picker). On Android 8.0, the camera (on the simulator) is working - see Gif. But on the Image Picker it simply dies. This is a production release but the same thing happens on a debug release.

Can anyone help me???

oreo8-camera-ok

profiVideos commented 6 years ago

Android-Screen-Videos.zip

I'm going to have to recompress the other two sample videos to get them under 10MB in size. I will post them ASAP as this has become a critical issue for me. At least the camera portion of the picker seems to be working for Oreo 8 on Android. I have since upgrade to picker code 0.19.3. So it#s as current as it gets.

I'll be back!!! :-)

OK. Now uploaded a zip file with two mp4 videos. One showing how the App works on Android 7.1.1 and the second how the app crashes on Android 8.0. As indicated earlier, it seems to be a problem with the image picker component and something that has changed rom version 7.1.1 to version 8.0.

And help or ideas would be greatly appreciated!!!!

Cheers, Markus

Karniej commented 6 years ago

Any fixes ready ?

alexcouret commented 6 years ago

@Karniej I ended up switching to https://github.com/react-community/react-native-image-picker because I'm okay with not having the crop or multiple image selection. You'll still need to add this to your AndroidManifest.xml between the application tags to make it work though:

<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>
Karniej commented 6 years ago

@OzoTek I have added this and still have the same problem, I'll double check on later if I don't have any bugs in the code... I would switch to this one too if I wouldn't need to crop the image.

alexcouret commented 6 years ago

@Karniej Yes this snippet only fixes the other lib, I couldn't make this one work with any of the fixes I found :/

ChrisFromCanada commented 6 years ago

I was having this issue. Trying to call ImagePicker.openCamera and it would crash trying to go to the camera.

I solved it.

Settings -> Apps -> Camera Click on Storage. Click "Clear Data". Click "Clear Cache".

Camera now opens and lets me crop perfectly... Hope it helps others.

ghost commented 6 years ago

I also came into this issue. For me, change to 'compileSdkVersion 27' and use 'com.android.support:appcompat-v7:27.0.2' can fix this issue.

ABibin commented 6 years ago

react-native-customized-image-picker, camera is not working in android 8.0. Any fixes found??

bosz commented 6 years ago

Am new to RN, having same issue here. Using RN 0.56 and react-native-image-crop-picker ^0.20.3

@LinZh107 please in which file did you change the 'com.android.support.appcompat-v7:27.0.2' ? It works on android 5 and 7 but fails on 4.*.

Am iced here, have lost over 8 days after release trying to fix this issue. Help please!!!

bosz commented 6 years ago

This is part of my android/gradle.build

ext {
    buildToolsVersion = "26.0.3"
    minSdkVersion = 16
    compileSdkVersion = 26
    targetSdkVersion = 26
    supportLibVersion = "26.1.0"
}

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 26
                buildToolsVersion '26.0.3'
            }
        }
    }
}

These are the dependencies of my android/app/build.gradle

dependencies {
    compile project(':react-native-image-crop-picker')
    compile project(':rn-fetch-blob')
    compile project(':react-native-vector-icons')
    compile project(':react-native-mauron85-background-geolocation')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    compile "com.facebook.react:react-native:+"  // From node_modules
}

Is there something i am missing here. Please, help.

ghost commented 6 years ago

@bosz Here is mine android/gradle.build looks like:

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:3.1.2"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenLocal()

        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        maven { url "$rootDir/../node_modules/react-native/android" }
        maven { url "https://jitpack.io" }
        maven { url "https://maven.google.com" }
    }
}

subprojects {
    // Do not change this one, because 'react-native-image-crop-picker' library using 27.+ version.
    // and if main project use a lower ver will cause app crash on opening cropping.
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == "com.android.support"
                    && !details.requested.name.contains("multidex")) {
                details.useVersion "27.1.0"
            }
        }
        afterEvaluate { project ->
            if (project.hasProperty("android")) {
                android {
                    compileSdkVersion 27
                    buildToolsVersion "27.0.3"
                    defaultConfig {
                        minSdkVersion 16
                        targetSdkVersion 26
                        versionCode 1
                        versionName "1.0"
                    }
                }
            }
        }
    }
}

and then give a specific version to com.android.support:appcompat-v7:{version} in your android/app/build.gradle

btw: my dev env is : "react-native": "0.55.4" Android Emulator version 8.1.0

fanlion commented 5 years ago

change

  android:authorities="${applicationId}.fileprovider"

to

  android:authorities="${applicationId}.provider"

is work for me, my project used rn-fetch-blob, maybe some conflict occurred in java module. I am not sure what will happen in your project....

origin xml code in my AndroidManifest.xml

<provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"    <!-- change this line work for me  -->
            android:grantUriPermissions="true"
            tools:replace="android:authorities"
            android:exported="false">
        <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                tools:replace="android:resource"
                android:resource="@xml/provider_paths"/>
    </provider>
jeremyfrancis commented 5 years ago

Got it! So I did react-native link react-native-image-crop-picker and got an error saying it couldn't find the MainApplication.java for android. Not sure why. But I went in and manually added in the package as shown in the "example" folder of react-native-image-crop-picker. Works fine now.

Garamani commented 5 years ago

For me the problem was using the pickSingle function from example folder without binding or using arrow function. after converting the pickSingle function to arrow function the problem was solved.

victorwpbastos commented 4 years ago

I fixed this by asking the permissions on Android and iOS (using react-native-permissions lib):

useEffect(() => {
    async function askPermissions() {
        if (Platform.OS === 'android') {
            await Permissions.requestMultiple([
                'android.permission.CAMERA',
                'android.permission.WRITE_EXTERNAL_STORAGE',
            ]);
        }

        if (Platform.OS === 'ios') {
            await Permissions.requestMultiple(['ios.permission.CAMERA', 'ios.permission.PHOTO_LIBRARY']);
        }
    }

    askPermissions();
}, []);
Arnab2021 commented 3 years ago
<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>

Can you please tell me what is applicationId or how i can get it ?

Rajmal12 commented 1 month ago

<?xml version="1.0" encoding="utf-8"?>

It will fetch from your app/build.gradle file