Reputation: 41
I have an issue with my react native app.
I am using expo-image-picker to take a picture and send it to firebase.
Here is my issue:
When building the apk for my app and using it that way on the Android Emulator on Windows, the App crashes every time I take or choose a picture.
This does not happen when using the app through Expo Go.
Here is the android log error:
--------- beginning of crash
02-09 11:13:42.098 3450 3450 E AndroidRuntime: FATAL EXCEPTION: main
02-09 11:13:42.098 3450 3450 E AndroidRuntime: Process: xxx.xxx.app, PID: 3450
02-09 11:13:42.098 3450 3450 E AndroidRuntime: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { }} to activity {xxx.xxx.app/xxx.xxx.app.MainActivity}: java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter mImageLoader
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at android.app.ActivityThread.deliverResults(ActivityThread.java:5015)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at android.app.ActivityThread.handleSendResult(ActivityThread.java:5056)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at android.os.Looper.loop(Looper.java:223)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7656)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: Caused by: java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter mImageLoader
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at expo.modules.imagepicker.exporters.CompressionImageExporter.<init>(Unknown Source:2)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at expo.modules.imagepicker.ImagePickerModule.handleOnActivityResult(ImagePickerModule.kt:397)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at expo.modules.imagepicker.ImagePickerModule.onActivityResult(ImagePickerModule.kt:315)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at expo.modules.adapters.react.services.UIManagerModuleWrapper$4.onActivityResult(UIManagerModuleWrapper.java:165)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at com.facebook.react.bridge.ReactContext.onActivityResult(ReactContext.java:305)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at com.facebook.react.ReactInstanceManager.onActivityResult(ReactInstanceManager.java:762)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at com.facebook.react.ReactDelegate.onActivityResult(ReactDelegate.java:90)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at com.facebook.react.ReactActivityDelegate.onActivityResult(ReactActivityDelegate.java:113)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at expo.modules.ReactActivityDelegateWrapper.onActivityResult(ReactActivityDelegateWrapper.kt:103)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at com.facebook.react.ReactActivity.onActivityResult(ReactActivity.java:69)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at android.app.Activity.dispatchActivityResult(Activity.java:8304)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: at android.app.ActivityThread.deliverResults(ActivityThread.java:5008)
02-09 11:13:42.098 3450 3450 E AndroidRuntime: ... 11 more
02-09 11:13:42.098 540 3609 I am_crash: [3450,0,xxx.xxx.app,950582852,java.lang.NullPointerException,Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter mImageLoader,NULL,2]
02-09 11:13:42.100 540 3609 W ActivityTaskManager: Force finishing activity xxx.xxx.app/.MainActivity
02-09 11:13:42.100 540 3609 I wm_finish_activity: [0,196218990,9,xxx.xxx.app/.MainActivity,force-crash]
02-09 11:13:42.100 540 3609 I wm_focused_stack: [0,0,1,9,finish-top adjustFocusToNextFocusableStack]
02-09 11:13:42.101 540 3609 I wm_task_moved: [8,1,2147483647]
02-09 11:13:42.100 540 3780 I DropBoxManagerService: add tag=data_app_crash isTagEnabled=true flags=0x2
02-09 11:13:42.101 540 3609 I wm_set_resumed_activity: [0,com.android.launcher3/.uioverrides.QuickstepLauncher,finish-top adjustFocusToNextFocusableStack]
02-09 11:13:42.109 314 314 D goldfish-address-space: claimShared: Ask to claim region [0x3f92ca000 0x3f9c2f000]
02-09 11:13:42.116 540 3609 I wm_pause_activity: [0,196218990,xxx.xxx.app/.MainActivity,userLeaving=false]
02-09 11:13:42.124 540 3609 I sysui_multi_action: [757,316,758,4,759,-1]
02-09 11:13:42.126 540 588 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.stats.service.DropBoxEntryAddedReceiver
02-09 11:13:42.126 540 588 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.chimera.GmsIntentOperationService$PersistentTrustedReceiver
02-09 11:13:42.132 3450 3450 I Process : Sending signal. PID: 3450 SIG: 9
02-09 11:13:42.145 1032 1060 I droid.launcher: Waiting for a blocking GC ProfileSaver
02-09 11:13:42.182 1032 1060 I droid.launcher: WaitForGcToComplete blocked ProfileSaver on HeapTrim for 37.227ms
02-09 11:13:42.188 540 903 I WindowManager: WIN DEATH: Window{8b15932 u0 xxx.xxx.app/xxx.xxx.app.MainActivity}
02-09 11:13:42.191 298 298 I Zygote : Process 3450 exited due to signal 9 (Killed)
02-09 11:13:42.231 540 590 I chatty : uid=1000(system) ActivityManager expire 3 lines
02-09 11:13:42.233 540 910 I ActivityManager: Process xxx.xxx.app (pid 3450) has died: prcp TOP
02-09 11:13:42.233 540 910 I am_proc_died: [0,3450,xxx.xxx.app,200,2]
02-09 11:13:42.233 540 910 I am_uid_stopped: 10121
02-09 11:13:42.234 3660 3660 I ActivityThread: Removing dead content
Here is my code:
const [image, setImage] = useState(null);
const [status, requestPermission] = ImagePicker.useCameraPermissions();
const pickImageFromCamera = async () => {
requestPermission().then(async () => {
let result = await ImagePicker.launchCameraAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
quality: 0,
});
if (!result.cancelled) {
setImage(result.uri);
}
});
};
const pickImageFromLibrary = async () => {
requestPermission().then(async () => {
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
quality: 0,
});
if (!result.cancelled) {
setImage(result.uri);
}
});
};
Here is my app.json
{
"expo": {
"name": "XXX XXX",
"slug": "XXXXXX",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./app/assets/icon.png",
"splash": {
"image": "./app/assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"plugins": [
[
"expo-image-picker",
{
"photosPermission": "The app accesses your photos to let you add them to your placement instructions or reports."
}
]
],
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true,
"infoPlist": {
"NSPhotoLibraryUsageDescription": "The app accesses your photos to let you add them to your placement instructions or reports.",
"NSCameraUsageDescription": "Allow $(PRODUCT_NAME) to access your camera",
"NSMicrophoneUsageDescription": "Allow $(PRODUCT_NAME) to access your microphone"
}
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./app/assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
},
"permissions": [
"android.permission.CAMERA",
"android.permission.READ_EXTERNAL_STORAGE",
"android.permission.WRITE_EXTERNAL_STORAGE",
"android.permission.RECORD_AUDIO"
],
"package": "xxx.xxx.app"
},
"web": {
"favicon": "./app/assets/favicon.png"
}
},
"infoPlist": {
"UIUserInterfaceStyle": "Light"
}
}
Thank you for any help!
Upvotes: 4
Views: 2890
Reputation: 669
Copying here the solution that worked for me from William Alexander response on this github issue
This is occurring when quality != 1
and allowEditing: false
The problem is mImageLoader is null. The reason for this is ImageLoaderInterface cannot be found. To fix that you need to
npm install expo-image-loader
expo-image-loader has that interface.
Then rebuild your .apk and it should be fine.
Thank you William !
Upvotes: 2