Ionic 6+Android10.0.0中OneSignal插件plugin_not_installed问题求助
解决Ionic 6 + OneSignal
plugin_not_installed 错误 以下是经过验证的解决方案,按顺序尝试:
1. 统一@awesome-cordova-plugins版本
你的项目中@awesome-cordova-plugins/core为5.43.0,但@awesome-cordova-plugins/onesignal是5.44.0,版本不一致可能引发兼容性问题:
npm install @awesome-cordova-plugins/onesignal@5.43.0
2. 彻底清理并重建环境
缓存或残留配置可能导致插件未正确安装:
# 删除依赖和锁文件 rm -rf node_modules package-lock.json npm install # 移除并重新添加Android平台 ionic cordova platform rm android ionic cordova platform add android@10.0.0 # 重新安装OneSignal插件 ionic cordova plugin rm onesignal-cordova-plugin ionic cordova plugin add onesignal-cordova-plugin@3.1.0
3. 确保Service正确注入且不被Tree-Shaking移除
- 在
OnesignalService中使用providedIn: 'root'声明注入:import { Injectable } from '@angular/core'; import { OneSignal } from '@awesome-cordova-plugins/onesignal/ngx'; @Injectable({ providedIn: 'root' }) export class OnesignalService { constructor(private oneSignal: OneSignal) {} OneSignalNotification() { // 先检查插件是否存在 if (!(window as any).plugins?.OneSignal) { console.error('OneSignal插件未加载'); return; } // 你的OneSignal初始化逻辑 this.oneSignal.startInit('YOUR_APP_ID'); // ...其他配置 this.oneSignal.endInit(); } } - 确保
app.module.ts中没有重复声明该Service(避免冲突)。
4. 配置Angular Prod构建允许CommonJS依赖
Prod构建的Tree-Shaking可能误删Cordova插件代码,在angular.json的生产构建配置中添加允许的依赖:
"projects": { "My App": { "architect": { "build": { "configurations": { "production": { "allowedCommonJsDependencies": [ "onesignal-cordova-plugin", "@awesome-cordova-plugins/onesignal" ] } } } } } }
5. 检查config.xml确认插件存在
手动打开项目根目录的config.xml,确认包含以下插件声明:
<plugin name="onesignal-cordova-plugin" spec="^3.1.0" />
6. 强化平台就绪后的错误处理
确保在platform.ready()完全resolved后再调用插件方法,同时添加错误捕获:
appInitialize() { this.platform.ready().then(async () => { this.statusBar.backgroundColorByHexString('#ff6657'); try { await this.oneSignal.OneSignalNotification(); } catch (err) { console.error('OneSignal初始化失败:', err); } }).catch(err => { console.error('平台就绪失败:', err); }); }
内容的提问来源于stack exchange,提问作者AziDev
相关产品推荐
相关产品推荐

