出现场景
使用ionic开发跨平台app时,需要使用推送,所以集成了push-notifications,但是在Android编译时出现以下错误。
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.iid.FirebaseInstanceId"
error:java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/iid/FirebaseInstanceId;
............
因为是个老项目,使用的是Capacitor2.0版本,无法升级为3.0的插件。所以只能找解决办法。
解决办法
根据错误提示,google了一下,发现是因为firebase这个版本的没有包含FirebaseInstanceId这个类了,使用的方式改变了,但是我们不想改代码。所以我们直接在android/app/build.gradle中添加FirebaseInstanceId依赖即可。
dependencies {
implementation platform('com.google.firebase:firebase-bom:28.0.1')
/// 增加这个库
implementation "com.google.firebase:firebase-iid"
}
然后sync,重新编译项目即可。
参考链接:Failed resolution of: Lcom/google/firebase/iid/FirebaseInstanceId
在使用Ionic 2.0开发跨平台应用并集成Push Notifications时遇到了Android编译错误,错误涉及FirebaseInstanceId类。由于项目为旧版本,无法直接升级插件。通过在android/app/build.gradle中添加FirebaseInstanceId依赖解决了问题。在dependencies块下添加'com.google.firebase:firebase-iid',然后同步并重新编译项目,成功解决了编译错误。
3035

被折叠的 条评论
为什么被折叠?



