E/CameraX: No default CameraXConfig.Provider specified in meta-data. The most likely cause is you did not include a default implementation in your build such as 'camera-camera2'. D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.photodiary, PID: 14550 java.lang.IllegalStateException: CameraX is not configured properly. The most likely cause is you did not include a default implementation in your build such as 'camera-camera2'. at androidx.camera.core.CameraX.<init>(CameraX.java:109) at androidx.camera.lifecycle.ProcessCameraProvider.getOrCreateCameraXInstance(ProcessCameraProvider.java:181) at androidx.camera.lifecycle.ProcessCameraProvider.getInstance(ProcessCameraProvider.java:167) at com.example.photodiary.Diary.startCamera(Diary.java:43) at com.example.photodiary.Diary.access$000(Diary.java:20) at com.example.photodiary.Diary$1.onClick(Diary.java:32) at android.view.View.performClick(View.java:7125) at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1131) at android.view.View.performClickInternal(View.java:7102) at android.view.View.access$3500(View.java:801) at android.view.View$PerformClick.run(View.java:27336) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) I/Process: Sending signal. PID: 14550 SIG: 9
时间: 2023-12-03 12:47:46 浏览: 144
Android CameraX 自学之路
5星 · 资源好评率100%
这个错误信息显示 CameraX 没有配置正确,最可能的原因是你的构建中没有包含默认的实现,例如 'camera-camera2'。你可以尝试在 AndroidManifest.xml 文件中添加以下 meta-data 标签来指定默认的 CameraXConfig.Provider :
```
<meta-data
android:name=" androidx.camera.default_config_provider"
android:value="camera2" />
```
这个 meta-data 标签指定了默认的 CameraXConfig.Provider 为 'camera2'。如果你已经在 build.gradle 文件中添加了相应的依赖,应该就可以解决这个问题了。如果还是无法解决问题,你可以考虑检查一下你的依赖是否正确,或者参考一下官方文档中的示例来进行调整。
阅读全文