簡體   English   中英

Capacitor/Ionic4:未安裝 plugin_not_installed 的 BarcodeScanner

[英]Capacitor/Ionic4: BarcodeScanner with plugin_not_installed

我在將 BarcodeScanner 添加到我的 android 構建時遇到問題,錯誤是plugin_not_installed

該應用程序編譯沒有任何錯誤,但它在運行時輸出錯誤。 我也試過刪除/添加 android 文件夾,但仍然沒有成功。

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

安裝:

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

應用程序模塊.ts:

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

@NgModule({
    ...

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

家.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

======

依賴項:

k

您剛剛為插件安裝了 ionic native wrapper,但沒有安裝插件

對於科爾多瓦

ionic cordova plugin add phonegap-plugin-barcodescanner

電容器用

npm install phonegap-plugin-barcodescanner

需要注意的重要一點是,如果您發出不帶“--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

然后在android上運行它,

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
      }
    );
  }

謝謝

當我遇到這個問題時,我正在使用帶電容器的實時重載。 在這里嘗試解決方案沒有成功之后,我只需要重建應用程序(當然在終端上按ctrl + c取消正在運行的應用程序之后):

 ionic cap run android -l --external

然后所有插件都成功運行。 我不知道每次添加插件時是否都必須這樣做,但現在可以

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM