Я делаю сканер штрих-кода с помощью конденсатора-mlkit/barcode-scanner и vue3. Я установил пакет сканера штрих-кода mlkit, тестирую его на своем устройстве Android, но когда я пытаюсь вызвать BarcodeScanner.scan(), вывод консоли в студии Android выглядит следующим образом:
File: https://localhost/assets/index-DFex7xUL.js - Line 13 - Msg: Error: The Google Barcode Scanner Module is not available. You must install it first.
Я знаю, что в этой ошибке четко указано, что не так, но я просто не понимаю, чего именно не хватает.
Мой компонент vue:
<script setup lang = "ts">
import { Barcode, BarcodeScanner } from "@capacitor-mlkit/barcode-scanning";
const startScanning = async () => {
const { barcodes } = await BarcodeScanner.scan();
};
</script>
<template>
<ion-page>
<ion-content>
<ion-fab-button @click = "startScanning()">
<ion-icon :icon = "scan"></ion-icon>
</ion-fab-button>
</ion-content>
</ion-page>
</template>
Android/приложение/build.gradle:
apply plugin: 'com.android.application'
android {
namespace "io.ionic.starter"
compileSdk rootProject.ext.compileSdkVersion
defaultConfig {
applicationId "io.ionic.starter"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
// Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
dataBinding true
}
dataBinding {
enabled = true
}
}
repositories {
flatDir{
dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"
implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion"
implementation project(':capacitor-android')
testImplementation "junit:junit:$junitVersion"
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
implementation project(':capacitor-cordova-android-plugins')
}
apply from: 'capacitor.build.gradle'
try {
def servicesJSON = file('google-services.json')
if (servicesJSON.text) {
apply plugin: 'com.google.gms.google-services'
}
} catch(Exception e) {
logger.info("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
}
Я попытался внести изменения в android/app/build.griddle, добавив
buildFeatures {
dataBinding true
}
dataBinding {
enabled = true
}
Я внес изменения в AndroidManifest.xml согласно документации.





Вам нужно вызвать метод installGoogleBarcodeScannerModule().