我很难将BarcodeScanner添加到我的android构建中,错误是BarcodeScanner。
该应用程序编译时没有任何错误,但它在运行时输出错误。我也尝试过删除/添加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
======
Dependencies:
发布于 2018-12-18 03:18:19
您刚刚为插件安装了离子型本机包装器,但没有安装插件。
科多瓦
ionic cordova plugin add phonegap-plugin-barcodescanner
电容器用
npm install phonegap-plugin-barcodescanner
发布于 2019-12-27 07:49:13
需要注意的是,如果您在没有“--保存”的情况下发出命令,有时package.json将不会被更新。例如,npm安装没有更新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
}
);
}
谢谢
发布于 2021-05-13 21:32:52
当我遇到这个问题的时候,我正在用电容进行现场重装。在这里尝试解决方案但没有成功之后,我只需要重新构建应用程序(当然,在终端上的ctrl
+ c
取消运行的应用程序之后):
ionic cap run android -l --external
然后所有插件都成功运行。我不知道每次我添加插件时是否都要这么做,但现在它还能用
https://stackoverflow.com/questions/53821200
复制