Expo ImagePicker does not return selected image from Camera and Image Library

  1. SDK Version: 46 (Managed)
  2. Platforms(Android/iOS/web/all): Android
  3. expo-image-picker: 13.3.1
  4. eas-cli: 2.3.0

We are using below code to get image either from Camera or Image Library and followed ImagePicker - Expo Documentation for the same:

import * as ImagePicker from 'expo-image-picker';

const pickImage = async () => {
	const hasPermission = await getMediaPermission();

	if (hasPermission) {
		let result = await ImagePicker.launchImageLibraryAsync({
			mediaTypes: ImagePicker.MediaTypeOptions.Images,
			aspect: [4, 3],
			base64: true
		});

		if (!result.cancelled) {
			setImage(result);
		}

		Alert.alert('', result?.uri); // Prints blank uri
	}
	else {
		Alert.alert('Grant Permission', 'Please grant Media Gallery permission.')
	}
};

const pickCamera = async () => {
	const hasPermission = await getCameraPermission();

	if (hasPermission) {
		let result = await ImagePicker.launchCameraAsync({
			mediaTypes: ImagePicker.MediaTypeOptions.Images,
			aspect: [4, 3],
			base64: true
		});

		if (!result.cancelled) {
			setImage(result);
		}

		Alert.alert('', result?.uri); // Prints blank uri
	}
	else {
		Alert.alert('Grant Permission', 'Please grant Camera permission.')
	}
};

const getMediaPermission = async () => {
	const { status: existingStatus } = await ImagePicker.getMediaLibraryPermissionsAsync();
	let finalStatus = existingStatus;
	if (existingStatus !== 'granted') {
		const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync();
		finalStatus = status;
	}

	return finalStatus === 'granted';
}

const getCameraPermission = async () => {
	const { status: existingStatus } = await ImagePicker.getCameraPermissionsAsync();
	let finalStatus = existingStatus;
	if (existingStatus !== 'granted') {
		const { status } = await ImagePicker.requestCameraPermissionsAsync();
		finalStatus = status;
	}

	return finalStatus === 'granted';
}

All works in Expo Go app but does not work in standalone apk or Google Play store published app. result object returned from both launchImageLibraryAsync and launchCameraAsync have empty uri. We are using EAS to build.

We also tried adding below to app.json under expo.android:

"permissions": [
	"CAMERA",
	"READ_EXTERNAL_STORAGE",
	"WRITE_EXTERNAL_STORAGE"
]

and below under expo.plugins:

[
	"expo-image-picker",
	{
	  "photosPermission": "The app needs photos access to add screenshot to support ticket.",
	  "cameraPermission": "The app needs camera access to add screenshot to support ticket."
	}
]

The issue was that we are using enableProguardInReleaseBuilds: true in app config. We had to update it as below to make this work:

[
  "expo-build-properties",
  {
    "android": {
      "enableProguardInReleaseBuilds": true,
      "extraProguardRules": "-keep class * implements expo.modules.kotlin.records.Record { *; } -keepclassmembers enum expo.modules.** { *; }"
    }
  }
]

Got this from [expo-image-picker] launchMediaLibraryAsync returns empty object in android release builds · Issue #19509 · expo/expo (github.com).

1 Like

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