Home » Android » Expo.ImagePicker works within Expo, but not in Standalone Android

Expo.ImagePicker works within Expo, but not in Standalone Android

Posted by: admin November 1, 2017 Leave a comment

Questions:

Our app allows the user take pictures (and select pictures) from it.

I’ve used the Expo component ImagePicker for that, as it provides a simple API.

And it works perfectly inside expo (both exp start and exp publish), but it does not work within a standalone apk.

When I try to invoke ImagePicker.launchCameraAsync(), I catch an EUNSPECIFIED exception, but that only in the standalone apk.

Details

An excerpt of the code:

import { ImagePicker } from 'expo';

(...)
const image = await ImagePicker.launchCameraAsync({
    allowsEditing: true,
    aspect: [3, 5],
});

(...)
let image = await ImagePicker.launchImageLibraryAsync({
    allowsEditing: true,
    aspect: [3, 5],
});

It works well within expo, including exp publish version.

As for my permissions in the app.json, what I have is the following:

(...)
"android": {
  "package": "br.com.miredefamilia",
  "versionCode": 3, 
  "permissions": [
    "android.permissions.CAMERA",
    "android.permissions.READ_INTERNAL_STORAGE",
    "android.permissions.READ_EXTERNAL_STORAGE"
  ]
}

I have also tried without the android.permissions.

The mobile does request for the permission, I accept it, and it does not launch the camera / picker, like it does within the expo.

Any help?

Answers:

The following changes have fixed the problem:

In the app.json

"android": {
  "package": "br.com.miredefamilia",
  "versionCode": 3, 
  "permissions": [
    "CAMERA",
    "READ_INTERNAL_STORAGE",
    "WRITE_INTERNAL_STORAGE",
    "READ_EXTERNAL_STORAGE",
    "WRITE_EXTERNAL_STORAGE"
  ]
}

And the calls to the component, I removed the parameters:

const image = await ImagePicker.launchCameraAsync();

let image = await ImagePicker.launchImageLibraryAsync();

I also removed the dependency:

"react-native-camera": "^0.10.0",

I don’t know exactly which one solved the problem, but one of them did.