Toxnyc
Toxnyc

Reputation: 1350

Capacitor/Ionic4: BarcodeScanner with plugin_not_installed

I am having trouble adding BarcodeScanner to my android build, the error was plugin_not_installed.

The app compiled without any errors, but it outputs the error on runtime. I have also tried removing/adding the android folder but still no luck.

Does anyone know what was causing this?

Install:

npm install --save @ionic-native/[email protected]

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

======

Dependencies:

k

Upvotes: 6

Views: 5747

Answers (3)

Cedric Ipkiss
Cedric Ipkiss

Reputation: 6347

I was using live reload with capacitor when I had this problem. After trying solutions here with no success, I just had to rebuild the app (after ctrl + c on the terminal to cancel the running app of course):

 ionic cap run android -l --external

All plugins then ran successfully. I don't know if I'm going to have to do this every time I add a plugin, but it works for now

Upvotes: 0

Manish
Manish

Reputation: 21

Important to note, sometimes package.json does not get updated if you give a command without "--save". For instance, npm install phonegap-plugin-barcodescanner was not updating config.xml and package.json. This might waste a lot of your time while getting the "Plugin_not_installed" error.

Follow the below steps and it should work seamlessly on android phones.

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

then run it on android,

ionic capacitor run android. 

Please note, the above solution is only if you are getting an error plugin_not_installed.

Sample Execution Code:

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

Thanks

Upvotes: 2

jcesarmobile
jcesarmobile

Reputation: 53341

You just installed the ionic native wrapper for the plugin, but not the plugin

For Cordova

ionic cordova plugin add phonegap-plugin-barcodescanner

For Capacitor

npm install phonegap-plugin-barcodescanner

Upvotes: 9

Related Questions