Image Picker Not Working in SDK 38

Please provide the following:

  1. SDK Version: 38
  2. Platforms(Android/iOS/web/all): Android
import * as ImagePicker from "expo-image-picker";
import * as Permissions from "expo-permissions";


handleEditAvatar = async () => {
    const { status } = await ImagePicker.requestCameraPermissionsAsync();
    const cameraRollPermission = await ImagePicker.requestCameraRollPermissionsAsync();
    if (status === "granted" && cameraRollPermission.status === "granted") {
      const result = await ImagePicker.launchImageLibraryAsync({
        allowsEditing: true,
        aspect: [4, 4],
        base64: true
      });
      if (!result.cancelled) {
        this.setState({ avatar: `data:image/png;base64,${result.base64}` });
      }
    } else if (Platform.OS === "ios") {
      Alert.alert(
        "No Permission",
        "Allow access to photos within this device.",
        [
          {
            text: "Go to setting",
            onPress: () => Linking.openURL("app-settings:")
          },
          {
            text: "Cancel",
            style: "cancel"
          }
        ],
        { cancelable: true }
      );
    }
  };

While starting with

expo start --no-dev --minify

Everything works fine

But the image picker is not working while making Api.

Hey @pandeykamal,

What is the behavior you are seeing? And what do you mean specifically by “not working while making Api”?

It doesn’t do anything instead it should allow me to pick the image i want to select.

Nothing is console logged? Can you put your code into a snack so I can test with my Android device?

handleEditAvatar = async () => {
      const result = await ImagePicker.launchImageLibraryAsync({
        allowsEditing: true,
        aspect: [4, 4],
        base64: true
      });
      if (!result.cancelled) {
        this.setState({ avatar: `data:image/png;base64,${result.base64}` });
      }
    } else if (Platform.OS === "ios") {
      Alert.alert(
        "No Permission",
        "Allow access to photos within this device.",
        [
          {
            text: "Go to setting",
            onPress: () => Linking.openURL("app-settings:")
          },
          {
            text: "Cancel",
            style: "cancel"
          }
        ],
        { cancelable: true }
      );
  };


Doing this works. Is it okay to not ask permisssion for android?

I have a similar issue. with Official tutorial, I fail to implement expo-image-picker:

[Fri Aug 28 2020 20:39:08.790]  WARN     Possible Unhandled Promise Rejection (id: 13):
TypeError: undefined is not an object (evaluating '_ExponentImagePicker.default.launchImageLibraryAsync')
launchImageLibraryAsync$@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:119621:45
tryCatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27531:23
invoke@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27704:32
tryCatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27531:23
invoke@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27604:30
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27634:19
tryCallTwo@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:29534:9
doResolve@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:29698:25
Promise@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:29557:14
callInvokeWithMethodAndArg@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27633:33
enqueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27638:157
async@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27655:69
launchImageLibraryAsync@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:119615:38
openImagePickerAsync$
tryCatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27531:23
invoke@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27704:32
tryCatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27531:23
invoke@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27604:30
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27634:19
tryCallTwo@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:29534:9
doResolve@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:29698:25
Promise@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:29557:14
callInvokeWithMethodAndArg@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27633:33
enqueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27638:157
async@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27655:69
onPress@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:57871:34
_performTransitionSideEffects@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:57422:22
_receiveSignal@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:57360:45
onResponderRelease@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:57278:34
invokeGuardedCallbackImpl@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:9728:21
invokeGuardedCallback@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:9822:42
invokeGuardedCallbackAndCatchFirstError@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:9826:36
executeDispatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:9931:48
executeDispatchesInOrder@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:9951:26
executeDispatchesAndRelease@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:10052:35
forEach@[native code]
forEachAccumulated@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:10042:22
runEventsInBatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:10076:27
runExtractedPluginEventsInBatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:10160:25
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:11200:42
batchedUpdates$1@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:23431:20
batchedUpdates@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:11138:36
_receiveRootNodeIDEvent@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:11199:23
receiveTouches@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:11229:34
__callFunction@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:3339:49
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:3061:31
__guard@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:3293:15
callFunctionReturnFlushedQueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:3060:21
callFunctionReturnFlushedQueue@[native code]
import React from "react";
import { Image, StyleSheet, Text, TouchableOpacity, View } from "react-native";
import * as Permissions from "expo-permissions";
import * as ImagePicker from "expo-image-picker";
import { Constants } from "react-native-unimodules";

export default function App() {
  let openImagePickerAsync = async () => {
    const options: ImagePicker.ImagePickerOptions = {
      allowsEditing: true,
      allowsMultipleSelection: true,
      aspect: [4, 4],
      base64: true,
      quality: 10,
    };
    const result = await ImagePicker.launchImageLibraryAsync(options); // error on here even when with no options
    console.log(result);
  };

  return (
    <View style={styles.container}>
      <Image source={{ uri: "https://i.imgur.com/TkIrScD.png" }} style={styles.logo} />
      <Text style={styles.instructions}>
        To share a photo from your phone with a friend, just press the button below!
      </Text>

      <TouchableOpacity onPress={openImagePickerAsync} style={styles.button}>
        <Text style={styles.buttonText}>Pick a photo</Text>
      </TouchableOpacity>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center",
  },
  logo: {
    width: 305,
    height: 189,
    marginBottom: 10,
  },
  instructions: {
    color: "#888",
    fontSize: 18,
    marginHorizontal: 15,
  },
  button: {
    backgroundColor: "blue",
    padding: 20,
    borderRadius: 5,
  },
  buttonText: {
    fontSize: 20,
    color: "#fff",
  },
});

Even when I copy and paste the guide (https://docs.expo.io/versions/v35.0.0/sdk/imagepicker/#usage) it totally make same error.

Nevermind. after close all, yarn android saved me. I think those dependencies (expo-image-picker and so on) is not updated to my physical phone

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.