reactjs - 电容器插件在 android build 上显示为未定义
问题描述
这是我找到的一个电容器插件https://github.com/JhonArlex/capacitor_qrcode 我希望它将它集成到我的 ionic 应用程序中,在 web 服务上它按预期工作,但是当我在 android 上尝试 livereload 时,错误屏幕弹出出来并说插件未定义..
import "capacitor_qrcode";
import { Plugins } from "@capacitor/core";
//..
await Plugins.QRCodePlugin.getCodeQR();
// QRCodePlugin is undefined?
我正在使用 Ionic React Capacitor ...如果您能提出任何其他方式我可以在我的应用程序中集成 QR 码扫描功能,我将不胜感激!谢谢!
解决方案
使用您自己的插件时,您需要将其注册/添加到您的 android MainActivity 中。 https://capacitor.ionicframework.com/docs/plugins/android#export-to-capacitor
像这样:
import com.jhon.capacitor_qrcode.QRCodePlugin;
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initializes the Bridge
this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
// Additional plugins you've installed go here
// Ex: add(TotallyAwesomePlugin.class);
add(QRCodePlugin.class);
}});
}
}
推荐阅读
- django - Django Rest Framework - 过滤数据的问题
- encryption - 是否真的可以解码/解密旧的 Msg Plus 聊天日志文件?
- swiftui - SwiftUI 按比例更改视图大小
- python - tkinter 小部件触发跟踪功能
- if-statement - 如何在 thymleaf 中使用多个条件 - “If 语句”
- python - Tensorflow 集线器错误“无法从 'tensorflow.python.tpu.tpu_embedding' 导入名称 'MomentumParameters'”
- firebase - 如何从firebase中的其他集合中查询?
- python - 熊猫通过不同的时间间隔和按列分组平均
- parceljs - 与 Parcel 2 一起使用的正确版本的变压器图像是什么?
- python - 使用 pyinstaller 将 py 转换为 exe 后导入 DLL 失败