I recently ejected my react-native project and the camera feature is not working. The code allows users to upload images. It works with expo but after eject and running with Android, it stopped working. This is code for the camera upload:
import * as Permissions from 'expo-permissions';import * as ImagePicker from 'expo-image-picker'; _checkPermissions = async () => { const { status } = await Permissions.askAsync(Permissions.CAMERA); this.setState({ camera: status }); // take permission for Gallery, aka CameraRoll const { statusRoll } = await Permissions.askAsync(Permissions.CAMERA_ROLL); this.setState({ cameraRoll: statusRoll }); }; findNewImage = async () => { this._checkPermissions(); let result = await ImagePicker.launchCameraAsync({ mediaTypes: "Images", allowsEditing: true, quality: 1 }); console.log("image picked is = result = ", result); if (!result.cancelled) { console.log("upload image"); this.setState({ imageSelected: true, imageId: this.uniqueId(), uri: result.uri }); } else { console.log("cancel"); this.setState({ imageSelected: false }); } };
However, I get this error:
W/ReactNativeJS: Possible Unhandled Promise Rejection (id: 3): TypeError: undefined is not an object (evaluating '_ExpoPermissions.default.askAsync') askAsync$@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:172905:109 tryCatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23066:23 invoke@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23241:32 tryCatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23066:23 invoke@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23142:30 http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23172:19 tryCallTwo@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24367:9 doResolve@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24531:25 Promise@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24390:14 callInvokeWithMethodAndArg@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23171:29 enqueue@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23176:157 async@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23192:69 askAsync@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:172896:38 _callee$@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:141098:71 tryCatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23066:23 invoke@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23241:32 tryCatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23066:23 invoke@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23142:30 http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23172:19 tryCallTwo@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24367:9 doResolve@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24531:25 Promise@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24390:14 callInvokeWithMethodAndArg@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23171:29 enqueue@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23176:157 async@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23192:69 _callee@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:141093:42 _callee2$@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:141141:40 tryCatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23066:23 invoke@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23241:32 tryCatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23066:23 invoke@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23142:30 http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23172:19 tryCallTwo@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24367:9 doResolve@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24531:25 Promise@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24390:14 callInvokeWithMethodAndArg@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23171:29 enqueue@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23176:157 async@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23192:69 _callee2@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:141137:42 onPress@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:141457:39 touchableHandlePress@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:51687:47 touchableHandlePress@[native code] _performSideEffectsForTransition@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:50367:36 _performSideEffectsForTransition@[native code] _recW/ReactNativeJS: Possible Unhandled Promise Rejection (id: 4): TypeError: undefined is not an object (evaluating '_ExponentImagePicker.default.launchCameraAsync') launchCameraAsync$@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:173085:45 tryCatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23066:23 invoke@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23241:32 tryCatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23066:23 invoke@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23142:30 http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23172:19 tryCallTwo@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24367:9 doResolve@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24531:25 Promise@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24390:14 callInvokeWithMethodAndArg@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23171:29 enqueue@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23176:157 async@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23192:69 launchCameraAsync@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:173079:38 _callee2$@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:141144:80 tryCatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23066:23 invoke@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23241:32 tryCatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23066:23 invoke@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23142:30 http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23172:19 tryCallTwo@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24367:9 doResolve@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24531:25 Promise@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24390:14 callInvokeWithMethodAndArg@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23171:29 enqueue@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23176:157 async@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23192:69 _callee2@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:141137:42 onPress@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:141457:39 touchableHandlePress@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:51687:47 touchableHandlePress@[native code] _performSideEffectsForTransition@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:50367:36 _performSideEffectsForTransition@[native code] _receiveSignal@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:50293:46 _receiveSignal@[native code] touchableHandleResponderRelease@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:50172:26 touchableHandleResponderRelease@[native code] invokeGuardedCallbackImpl@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8533:21 invokeGuardedCallback@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8624:42 invokeGuardedCallbackAndCatchFirstError@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8628:36 executeDispatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8822:48 executeDispatchesInOrder@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8842:26 executeDispatchesAndRelease@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8937:35 forEach@[native code] forEachAccumulated@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8927:22 runEventsInBatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:9031:27 runExtrac
There is an upload button in my app and when I click it, this error message comes up in Android Studio console. It was working fine with Expo.
Here is my package.json:
{"scripts": {"start": "react-native start","android": "react-native run-android","ios": "react-native run-ios","web": "expo start --web" },"dependencies": {"@expo/samples": "~3.0.0","@expo/vector-icons": "^10.0.2","@unimodules/core": "^2.0.1","@unimodules/react-native-adapter": "^2.0.1","expo-asset": "^5.0.0","expo-constants": "^5.0.0","expo-file-system": "^5.0.1","expo-font": "^5.0.0","expo-image-picker": "^5.0.2","expo-permissions": "^5.0.1","expo-web-browser": "^5.0.0","firebase": "^6.1.1","react": "16.8.3","react-dom": "^16.8.6","react-native": "0.59.8","react-native-elements": "^1.1.0","react-native-gesture-handler": "^1.3.0","react-native-paper": "^2.16.0","react-native-permissions": "^1.1.1","react-native-vector-icons": "^6.5.0","react-native-web": "^0.11.4","react-navigation": "^3.11.0","react-navigation-material-bottom-tabs": "^1.0.0","remove-node-modules": "^1.7.4" },"devDependencies": {"babel-preset-expo": "^5.1.0" },"private": true}