Photo capture crash on Android 11

2,633 views
Skip to first unread message

Martynas Jegorovas

unread,
Jul 13, 2020, 5:15:22 AM7/13/20
to Android CameraX Discussion Group
Hello,
While trying to capture an image app crashes and doesn't produce the image. Issue is similar to this, but while testing on Pixel 3 XL (emulated API R) everything worked correctly, so that leads me to suspect that something is wrong with android 11 version. Crash is reproducible on 'CameraXBasic' sample app too.

Device: Pixel 3a XL (API 30) - emulated
Build number: sdk_gphone_x86_arm-userdebug 11 RPB2.200611.009 6625208 dev-keys

Crash (back camera):
2020-07-13 11:56:09.694 17093-17134/com.android.example.cameraxbasic E/CameraCaptureSession: Session 0: Exception while stopping repeating:
    android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): cancelRequest:459: Camera 0: Error clearing streaming request: Function not implemented (-38)
        at android.hardware.camera2.CameraManager.throwAsPublicException(CameraManager.java:1009)
        at android.hardware.camera2.impl.ICameraDeviceUserWrapper.cancelRequest(ICameraDeviceUserWrapper.java:99)
        at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:1263)
        at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:578)
        at android.hardware.camera2.impl.CameraCaptureSessionImpl$2.onDisconnected(CameraCaptureSessionImpl.java:789)
        at android.hardware.camera2.impl.CameraDeviceImpl$7.run(CameraDeviceImpl.java:245)
        at androidx.camera.core.impl.utils.executor.SequentialExecutor$1.run(SequentialExecutor.java:110)
        at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.workOnQueue(SequentialExecutor.java:230)
        at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.run(SequentialExecutor.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)
     Caused by: android.os.ServiceSpecificException: cancelRequest:459: Camera 0: Error clearing streaming request: Function not implemented (-38) (code 10)
        at android.os.Parcel.createExceptionOrNull(Parcel.java:2387)
        at android.os.Parcel.createException(Parcel.java:2357)
        at android.os.Parcel.readException(Parcel.java:2340)
        at android.os.Parcel.readException(Parcel.java:2282)
        at android.hardware.camera2.ICameraDeviceUser$Stub$Proxy.cancelRequest(ICameraDeviceUser.java:732)
        at android.hardware.camera2.impl.ICameraDeviceUserWrapper.cancelRequest(ICameraDeviceUserWrapper.java:97)
        at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:1263)
        at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:578)
        at android.hardware.camera2.impl.CameraCaptureSessionImpl$2.onDisconnected(CameraCaptureSessionImpl.java:789)
        at android.hardware.camera2.impl.CameraDeviceImpl$7.run(CameraDeviceImpl.java:245)
        at androidx.camera.core.impl.utils.executor.SequentialExecutor$1.run(SequentialExecutor.java:110)
        at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.workOnQueue(SequentialExecutor.java:230)
        at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.run(SequentialExecutor.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)

Also, interesting error message is displayed in the log while capturing a photo with front camera on said device even though the image is saved to directory:
2020-07-13 12:11:16.313 17629-17894/com.android.example.cameraxbasic E/CameraXBasic: Photo capture failed: Failed to write or close the file
    androidx.camera.core.ImageCaptureException: Failed to write or close the file
        at androidx.camera.core.ImageCapture$3.onError(ImageCapture.java:668)
        at androidx.camera.core.ImageSaver.lambda$postError$1$ImageSaver(ImageSaver.java:263)
        at androidx.camera.core.-$$Lambda$ImageSaver$eAp-cZyzsEk-LVLazzLE-ezQzwo.run(Unknown Source:8)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)
     Caused by: java.io.IOException: close failed: ENOENT (No such file or directory)
        at libcore.io.IoBridge.closeAndSignalBlockedThreads(IoBridge.java:254)
        at java.io.FileOutputStream.close(FileOutputStream.java:431)
        at androidx.camera.core.ImageSaver.run(ImageSaver.java:155)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)
     Caused by: android.system.ErrnoException: close failed: ENOENT (No such file or directory)
        at libcore.io.Linux.close(Native Method)
        at libcore.io.ForwardingOs.close(ForwardingOs.java:88)
        at libcore.io.BlockGuardOs.close(BlockGuardOs.java:110)
        at libcore.io.ForwardingOs.close(ForwardingOs.java:88)
        at libcore.io.IoBridge.closeAndSignalBlockedThreads(IoBridge.java:252)
        at java.io.FileOutputStream.close(FileOutputStream.java:431)
        at androidx.camera.core.ImageSaver.run(ImageSaver.java:155)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)

Scott Nien

unread,
Jul 14, 2020, 5:22:37 AM7/14/20
to Martynas Jegorovas, Android CameraX Discussion Group
Hi , 

>   android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): cancelRequest:459: Camera 0: Error clearing streaming request: Function not implemented (-38)
I think this is an emulator camera HAL problem.  And emulator camera HAL is not stable sometimes and I think it is worse with android 11 beta.  
I don't think it is worth digging into the emulator + android 11 beta issue for now.   
Can you test it on real devices with android 11 and see if the issue still remains ?  


>2020-07-13 12:11:16.313 17629-17894/com.android.example.cameraxbasic E/CameraXBasic: Photo capture failed: Failed to write or close the file
  > androidx.camera.core.ImageCaptureException: Failed to write or close the file

The problem is on Pixel 3A api 30 emulator ,  Context#getExternalMediaDirs() returns "/storage/emulated/0/Android/media/com.android.example.cameraxbasic/CameraX Basic"
but "/storage/emulated" is permission denied .     Not sure if it is related to scoped storage changes in android 11. 


--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/9a8dfda9-463b-4496-9513-580df3369808o%40android.com.

MJegorovas

unread,
Jul 14, 2020, 9:07:50 AM7/14/20
to Android CameraX Discussion Group, Scott Nien, Android CameraX Discussion Group, MJegorovas
Hello again,
Thanks for the answer. I tested on a real device and the second message still gets displayed in the logcat (the 'Photo captured failed' one). I would like to emphasize that the photo does get taken and stored in the storage - if I click on last image taken button it gets displayed properly.
Device: Pixel 3a
Build number: RPB2.200611.009

Scott Nien

unread,
Jul 14, 2020, 10:32:29 PM7/14/20
to MJegorovas, Android CameraX Discussion Group
Yes,  I also can reproduce it on real pixel devices with android 11.  

I think this relates to the android 11 scope storage changes.   And it can be fixed by adding 
        android:requestLegacyExternalStorage="true"
to the <application> in AndroidManifest.xml.      Please note that you might need to uninstall the app and install again to make it effective. 

I know the android:requestLegacyExternalStorage should be ignored in android 11 according to the documentation  , but somehow it does affect the behavior in android 11 beta now. 
and the behavior will probably be changed in the future since it is still in beta. 

While we will still look for improving the CameraXBasic for android 11 compatibility,   if you app is to take photos and store it in the public storage that allows other apps to access (with permission of course) ,  then you probably should use media store which is the recommended way in the scoped storage environment.  

AL HO

unread,
Jul 15, 2020, 5:04:44 AM7/15/20
to Android CameraX Discussion Group, Scott Nien, Android CameraX Discussion Group, MJegorovas
Beside set flag "android:requestLegacyExternalStorage".
If you app is running on Android 11, Android also checks the target sdk version.
If the target sdk version is <= 29, the flag still workable.
If you set target sdk version > 29, this flag will be ignored.

Scott Nien

unread,
Jul 27, 2020, 10:50:07 AM7/27/20
to AL HO, Android CameraX Discussion Group, MJegorovas
Hi , 

Regarding the emulator issue,    there is a public issue opened to track it. 

Please cc yourself if you want to get the latest update. 

Reply all
Reply to author
Forward
0 new messages