5

我在将 BarcodeScanner 添加到我的 android 版本时遇到问题,错误是plugin_not_installed

该应用程序编译时没有任何错误,但它在运行时输出错误。我也尝试过删除/添加 android 文件夹,但仍然没有运气。

有谁知道这是什么原因造成的?

安装:

npm install --save @ionic-native/barcode-scanner@5.0.0-beta.21

app.module.ts:

import { BarcodeScanner } from '@ionic-native/barcode-scanner/ngx';

@NgModule({
    ...

    providers: [
        ...
        BarcodeScanner
        ...
    ]
    ...
})

home.ts:

import { BarcodeScanner, BarcodeScannerOptions } from '@ionic-native/barcode-scanner/ngx';

@Component({
  ...
})
export class HomePage implements OnInit {
  private options: BarcodeScannerOptions;

  constructor(private barcodeScanner: BarcodeScanner) {}

  scan() {
    this.options = {
      prompt: "Scan your qrcode "
    }
    this.barcodeScanner.scan(this.options).then((barcodeData) => {
      ...
    }, err => {
      console.log("Error occured : " + err);
    });
  }//func scan

}//class HomePage

======

依赖项:

ķ

4

3 回答 3

9

您刚刚为插件安装了离子原生包装器,但没有安装插件

对于科尔多瓦

ionic cordova plugin add phonegap-plugin-barcodescanner

电容器用

npm install phonegap-plugin-barcodescanner

于 2018-12-18T11:18:19.283 回答
2

需要注意的重要一点是,如果您给出没有“--save”的命令,有时 package.json 不会更新。例如,npm install phonegap-plugin-barcodescanner 没有更新 config.xml 和 package.json。在出现“Plugin_not_installed”错误时,这可能会浪费您的大量时间。

请按照以下步骤操作,它应该可以在 Android 手机上无缝运行。

npm install @ionic-native/barcode-scanner --save
npm install phonegap-plugin-barcodescanner --save
npx cap sync

然后在安卓上运行,

ionic capacitor run android. 

请注意,上述解决方案仅适用于您收到错误 plugin_not_installed。

示例执行代码:

declare let window: any;

  scan(){
    window.cordova.plugins.barcodeScanner.scan(
      result => console.log(result),
      err => this.presentAlert(err),
      {
        showTorchButton: true,
        prompt: "Scan your code",
        formats: "QR_CODE",
        resultDisplayDuration: 0
      }
    );
  }

谢谢

于 2019-12-27T15:49:13.833 回答
0

当我遇到这个问题时,我正在使用带电容器的实时重载。在这里尝试解决方案没有成功后,我只需要重建应用程序(当然在终端上ctrl+c取消正在运行的应用程序之后):

 ionic cap run android -l --external

然后所有插件都成功运行。我不知道每次添加插件时是否都必须这样做,但它现在可以使用

于 2021-05-14T05:32:52.570 回答