You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

华为设备上CameraX无法生成JPEG文件问题求助

问题背景
  • 两台同型号华为设备出现异常,此前3个月应用运行稳定,多设备已成功处理数千张图片
  • 异常触发流程:图片处理服务无法找到CameraX应生成的文件,抛出java.io.FileNotFoundException,后续因尝试访问空Bitmap的getWidth()方法引发致命空指针崩溃
  • 当前状态:应用重装后恢复正常,但无法复现异常,且无设备日志权限,需定位问题根源
完整异常日志(翻译后)
2023-11-09 14:39:04.044 26047-26047 HwViewRootImpl          atche.surveyorapplication            信息  removeInvalidNode:卡顿列表中的所有节点均已过期
2023-11-09 14:39:04.072 26047-26047 AudioManager            atche.surveyorapplication            详细  查询音效启用状态...
2023-11-09 14:39:04.109 26047-26047 MediaPlayerNative       atche.surveyorapplication            信息  准备MediaPlayer(0xb5286d40)
2023-11-09 14:39:04.137 26047-26275 MediaPlayerNative       atche.surveyorapplication            调试  消息:MEDIA_PREPARED(1), ext1=0, ext2=0x0
2023-11-09 14:39:04.137 26047-26047 MediaPlayerNative       atche.surveyorapplication            信息  准备完成 - 状态=0 MediaPlayer(0xb5286d40)
2023-11-09 14:39:04.159 26047-26047 PlayerBase              atche.surveyorapplication            详细  baseStart() piid=3607
2023-11-09 14:39:04.164 26047-26047 MediaPlayer             atche.surveyorapplication            信息  [HSM] 保持唤醒状态 true uid: 10117, pid: 26047
2023-11-09 14:39:04.167 26047-26047 MediaPlayerNative       atche.surveyorapplication            警告  操作:启动,当前状态:MEDIA_PLAYER_STARTED
2023-11-09 14:39:04.202 26047-26047 ImageCapture            atche.surveyorapplication            调试  执行takePictureInternal
2023-11-09 14:39:04.209 26047-26047 CameraOrientationUtil   atche.surveyorapplication            调试  获取相对图片旋转角度:目标旋转角度=0,源旋转角度=90,是否反向拍摄=true,结果=90
2023-11-09 14:39:04.212 26047-26047 TakePictureManager      atche.surveyorapplication            调试  发起下一个拍照请求
2023-11-09 14:39:04.242 26047-26493 Camera2CameraImpl       atche.surveyorapplication            调试  {Camera@65d1208[id=0]} 发起捕获请求
2023-11-09 14:39:04.243 26047-26493 CaptureSession          atche.surveyorapplication            调试  正在发起捕获请求
2023-11-09 14:39:04.248 26047-26493 Camera2CaptureRequestBuilder atche.surveyorapplication            调试  创建捕获请求
2023-11-09 14:39:04.280 26047-26275 MediaPlayerNative       atche.surveyorapplication            调试  消息:未知媒体事件类型(6), ext1=0, ext2=0x0
2023-11-09 14:39:04.287 26047-26078 Gralloc3                atche.surveyorapplication            警告  不支持3.x版本的分配器
2023-11-09 14:39:04.576 26047-26047 TakePictureManager      atche.surveyorapplication            调试  发起下一个拍照请求
2023-11-09 14:39:04.576 26047-26047 TakePictureManager      atche.surveyorapplication            调试  无新请求
2023-11-09 14:39:04.812 26047-26725 BitmapFactory           atche.surveyorapplication            错误  无法解码流:java.io.FileNotFoundException: /data/user/0/atche.surveyorapplication/2023.11.07  08-27-32.0.jpeg: 打开失败:ENOENT(没有该文件或目录)
2023-11-09 14:39:04.813 26047-26725 System.err              atche.surveyorapplication            警告  java.io.FileNotFoundException: /data/user/0/atche.surveyorapplication/2023.11.07  08-27-32.0.jpeg: 打开失败:ENOENT(没有该文件或目录)
2023-11-09 14:39:04.813 26047-26725 System.err              atche.surveyorapplication            警告      at libcore.io.IoBridge.open(IoBridge.java:496)
2023-11-09 14:39:04.813 26047-26725 System.err              atche.surveyorapplication            警告      at java.io.FileInputStream.<init>(FileInputStream.java:159)
2023-11-09 14:39:04.813 26047-26725 System.err              atche.surveyorapplication            警告      at java.io.FileInputStream.<init>(FileInputStream.java:115)
2023-11-09 14:39:04.814 26047-26725 System.err              atche.surveyorapplication            警告      at androidx.exifinterface.media.ExifInterface.initForFilename(ExifInterface.java:5283)
2023-11-09 14:39:04.814 26047-26725 System.err              atche.surveyorapplication            警告      at androidx.exifinterface.media.ExifInterface.<init>(ExifInterface.java:3946)
2023-11-09 14:39:04.814 26047-26725 System.err              atche.surveyorapplication            警告      at atche.surveyorapplication.PictureProcessingService.getImageExifOrientation(PictureProcessingService.kt:385)
2023-11-09 14:39:04.814 26047-26725 System.err              atche.surveyorapplication            警告      at atche.surveyorapplication.PictureProcessingService.access$getImageExifOrientation(PictureProcessingService.kt:34)
2023-11-09 14:39:04.814 26047-26725 System.err              atche.surveyorapplication            警告      at atche.surveyorapplication.PictureProcessingService$ServiceHandler.handleMessage(PictureProcessingService.kt:104)
2023-11-09 14:39:04.814 26047-26725 System.err              atche.surveyorapplication            警告      at android.os.Handler.dispatchMessage(Handler.java:110)
2023-11-09 14:39:04.814 26047-26725 System.err              atche.surveyorapplication            警告      at android.os.Looper.loop(Looper.java:219)
2023-11-09 14:39:04.814 26047-26725 System.err              atche.surveyorapplication            警告      at android.os.HandlerThread.run(HandlerThread.java:67)
2023-11-09 14:39:04.814 26047-26725 System.err              atche.surveyorapplication            警告  引起原因:android.system.ErrnoException: 打开失败:ENOENT(没有该文件或目录)
2023-11-09 14:39:04.814 26047-26725 System.err              atche.surveyorapplication            警告      at libcore.io.Linux.open(Native Method)
2023-11-09 14:39:04.814 26047-26725 System.err              atche.surveyorapplication            警告      at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
2023-11-09 14:39:04.815 26047-26725 System.err              atche.surveyorapplication            警告      at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
2023-11-09 14:39:04.815 26047-26725 System.err              atche.surveyorapplication            警告      at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
2023-11-09 14:39:04.815 26047-26725 System.err              atche.surveyorapplication            警告      at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8198)
2023-11-09 14:39:04.815 26047-26725 System.err              atche.surveyorapplication            警告      at libcore.io.IoBridge.open(IoBridge.java:482)
2023-11-09 14:39:04.815 26047-26725 System.err              atche.surveyorapplication            警告      ... 10 个更多调用栈
2023-11-09 14:39:04.815 26047-26725 QarthLog                atche.surveyorapplication            信息  [补丁存储] 创建禁用异常Qarth文件
2023-11-09 14:39:04.816 26047-26725 QarthLog                atche.surveyorapplication            信息  [补丁存储] 为atche.surveyorapplication创建禁用文件,uid为10117
2023-11-09 14:39:04.817 26047-26725 AndroidRuntime          atche.surveyorapplication            错误  致命异常:ServiceStartArguments 进程:atche.surveyorapplication,PID: 26047 java.lang.NullPointerException: 尝试调用空对象引用的虚拟方法'int android.graphics.Bitmap.getWidth()'
2023-11-09 14:39:04.817 26047-26725 AndroidRuntime          atche.surveyorapplication            错误      at atche.surveyorapplication.PictureProcessingService$ServiceHandler.handleMessage(PictureProcessingService.kt:114)
2023-11-09 14:39:04.817 26047-26725 AndroidRuntime          atche.surveyorapplication            错误      at android.os.Handler.dispatchMessage(Handler.java:110)
2023-11-09 14:39:04.817 26047-26725 AndroidRuntime          atche.surveyorapplication            错误      at android.os.Looper.loop(Looper.java:219)
2023-11-09 14:39:04.817 26047-26725 AndroidRuntime          atche.surveyorapplication            错误      at android.os.HandlerThread.run(HandlerThread.java:67)
2023-11-09 14:39:04.837 26047-26725 Process                 atche.surveyorapplication            信息  发送信号。PID: 26047 SIG: 9
排查方向
  • 文件命名与路径兼容性:目标文件名包含空格和特殊格式,需检查CameraX的文件生成逻辑是否在华为设备上存在命名兼容性问题,比如系统对带空格的文件路径解析异常
  • CameraX文件写入完整性:CameraX完成拍照请求后,可能因华为设备的存储权限临时变更、系统自动清理机制(如后台清理应用文件)导致文件未成功写入或被删除,需验证存储权限的动态申请逻辑,以及是否有后台进程影响文件留存
  • 时间戳逻辑错误:拍照触发时间为11-09,但尝试加载的文件时间戳为11-07,需排查是否存在缓存文件未及时清理、服务错误加载历史文件的逻辑问题
  • 华为系统特性限制:华为设备的HwViewRootImpl、存储管理机制可能存在特殊处理,比如应用后台运行时的文件访问限制,需检查应用在后台状态下的文件访问权限是否被系统拦截
  • 异常处理缺失:FileNotFoundException未被捕获,导致后续操作触发空指针崩溃,需先完善异常捕获逻辑,在文件操作前增加存在性校验,同时记录文件生成路径、写入结果等上下文信息,便于后续复现排查

内容的提问来源于stack exchange,提问作者Alex

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 09:09:51