[] crashes on Android (New Architecture + Hermes) with selectionLimit: 1
Using react-native-image-picker on Android with the New Architecture + Hermes. When calling launchImageLibrary with selectionLimit: 1, the app crashes immediately with:
com.facebook.react.common.JavascriptException:
Error: Exception in HostFunction: Could not enqueue microtask
because they are disabled in this runtime, js engine: hermes
setimmediate@1:235518Workaround that works:
Declaring options as any and setting selectionLimit: 2 (then only using assets[0]), which mirrors the pattern used internally for multi-image selection:
const options: any = {
mediaType: 'photo',
selectionLimit: Platform.OS === 'android' ? 2 : 1,
// ...rest of options
};
launchImageLibrary(options, (response) => {
const imageUri = response.assets?.[0]?.uri;
// ...
});What doesn't work:
selectionLimit: 1 with typed ImageLibraryOptions → crash
selectionLimit: 0 → works but allows unlimited selection
selectionLimit: 2 with typed ImageLibraryOptions → still crashes (the any type seems to matter)
Questions:
Why does selectionLimit: 1 specifically trigger the native Android Photo Picker instead of the internal RN selector?
Why does using options: any vs ImageLibraryOptions affect the behavior at runtime? Is there some transformation happening in the typed path?
Is there a cleaner fix than this workaround?
Environment:
react-native-image-picker: ^7.1.0
react-native: 0.77.3
New Architecture: enabled
JS engine: Hermes
minSdkVersion: 24
targetSdkVersion: 35
compileSdkVersion: 35
buildToolsVersion: 35.0.0
kotlinVersion: 2.0.21
ndkVersion: 28.0.12433566
Source: react-native-image-picker/react-native-image-picker