Skip to content

LibX camera error

Wed 25 Sep 2024  
🎉 Hi: ... 🎉

Android

สาเหตุ เกิดจากการ Conflict Package @capacitor-community/camera-preview และ @capacitor-mlkit/barcode-scanning ทำให้เมื่อ Run LibX บน Android จะไม่สามาถเปิดกล้องได้ พื้นหลังจะเป็นสีขาว

วิธีแก้ไข เพิ่มไฟล์ src-capacitor/android/app/src/main/res/layout/bridge_layout_main.xml จะทำให้เปิดกล้องได้ พื้นหลังโปร่งใส

xml
<!-- bridge_layout_main.xml -->

<?xml version="1.0" encoding="utf-8"?>

<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.getcapacitor.BridgeActivity">

    <androidx.camera.view.PreviewView
        android:id="@+id/preview_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

Built with: VitePress.