出现场景
使用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