React-native-image-crop-picker: Android permissions error: Required permission missing

Created on 29 Sep 2020  路  6Comments  路  Source: ivpusic/react-native-image-crop-picker

Version

Tell us which versions you are using:

  • react-native-image-crop-picker v0.35.0
  • react-native v0.63.2
  • gradle stuff
    buildToolsVersion = "29.0.3"
    ext.kotlin_version = '1.3.21'
    minSdkVersion = 19
    compileSdkVersion = 29
    targetSdkVersion = 29

Platform

  • Android only (iOS works correctly)

Expected behaviour

I should be able to open camera and/or cropper

Actual behaviour

Continually getting ambiguous error 'Error: Required permission missing' when attempting to call any ImagePicker methods

Steps to reproduce

  1. Follow android install steps as of Sept 29th 2020

  2. Attempt to call ImagePicker.openCamera() or ImagePicker.openCropper()

3.

Attachments

Receiving this error.

Error: Required permission missing
    at Object.promiseMethodWrapper [as openCamera] (NativeModules.js:103)
    at CollagePhotoFrame._this.cropPhoto (CollagePhotoFrame.js:18)
    at onPress (CollagePhotoFrame.js:81)
    at Pressability._performTransitionSideEffects (Pressability.js:697)
    at Pressability._receiveSignal (Pressability.js:634)
    at onResponderRelease (Pressability.js:530)
    at Object.invokeGuardedCallbackImpl (ReactNativeRenderer-dev.js:265)
    at invokeGuardedCallback (ReactNativeRenderer-dev.js:476)
    at invokeGuardedCallbackAndCatchFirstError (ReactNativeRenderer-dev.js:500)
    at executeDispatch (ReactNativeRenderer-dev.js:597)

I have the permissions set in AndroidManifest for CAMERA, WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE
I've tried explicitly asking for permissions like so.

componentDidMount() {
    PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE)
    PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE)
    PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.CAMERA)
  }

I've noticed WRITE_EXTERNAL_STORAGE always returns 'never_ask_again' no matter what the user does.
I've tried rolling back to '0.32.2' to no avail.
I've tried setting sdk target and compile version to 27 but that breaks other things in the app so I couldn't test.
I've also set android:requestLegacyExternalStorage="true" in AndroidManifest to no avail.
I've tried running on a simulator running android 10, a simulator running android 9, a OnePlus 7 running android 10.2, and a OnePlus 5 running android 10.

Most helpful comment

WRITE_EXTERNAL_STORAGE seems like it needs a wee bit more permission than normal.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace" />

seems to work for me

All 6 comments

I've found out that if I go into the source to PickerModule.java and disable the permission check, the cropper appears to work correctly. My java skills are pretty much non existent so I can't say where the problem stems from.
PickerModule.java

@ReactMethod
    public void openCropper(final ReadableMap options, final Promise promise) {
        final Activity activity = getCurrentActivity();

        if (activity == null) {
            promise.reject(E_ACTIVITY_DOES_NOT_EXIST, "Activity doesn't exist");
            return;
        }

        setConfiguration(options);
        resultCollector.setup(promise, false);

        final Uri uri = Uri.parse(options.getString("path"));
        // permissionsCheck(activity, promise, Collections.singletonList(Manifest.permission.WRITE_EXTERNAL_STORAGE), new Callable<Void>() {
            // @Override
            // public Void call() {
                startCropping(activity, uri);
                // return null;
            // }
        // });
    }

Android changed to only asking permissions the moment you need them. So you can't pre-ask a permission anymore at app start for example. So where it used to just ask for that permission, even though it did not need it, now the Android system suppresses the permissions request, and the check still throws. As long as you are supporting a minSdk version of 19, this appears to be safely removable.

WRITE_EXTERNAL_STORAGE seems like it needs a wee bit more permission than normal.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace" />

seems to work for me

WRITE_EXTERNAL_STORAGE seems like it needs a wee bit more permission than normal.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace" />

seems to work for me

you just saved my day @initialsaet, not gonna lie! thanks!

@initialsaet Thank you so much! What a life saver!

I think this should be highlighted in the README. @initialsaet 's solution is working.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aterribili picture aterribili  路  3Comments

co-de picture co-de  路  3Comments

DISKONEKTeD picture DISKONEKTeD  路  3Comments

victorwpbastos picture victorwpbastos  路  3Comments

Phenek picture Phenek  路  3Comments