配置react-native-fcm时触发:app:transformClassesWithMultidexlistForDebug任务失败
解决react-native-fcm配置时的Multidex构建错误
我经常碰到React Native集成FCM时出现这个Multidex列表生成失败的问题,结合你给出的版本信息(RN 0.55.2、Android API 23、react-native-fcm 14.1.3),给你几个针对性的解决步骤,应该能搞定:
开启Multidex支持
API 23本身支持Multidex,但你的项目可能没显式配置。修改android/app/build.gradle:- 在
defaultConfig块中添加:multiDexEnabled true - 在
dependencies块中添加依赖:implementation 'com.android.support:multidex:1.0.3' - 如果你有自定义的Application类,让它继承
MultiDexApplication;如果没有,修改AndroidManifest.xml里的Application标签:<application android:name="android.support.multidex.MultiDexApplication" <!-- 其他属性 --> >
- 在
清理构建缓存
旧缓存很可能导致这类奇怪的构建错误,执行以下命令:# 清理Android构建缓存 cd android && ./gradlew clean && cd .. # 重置React Native缓存 react-native start --reset-cache检查顶级build.gradle的Google Services配置
确保android/build.gradle里的google-services classpath版本和你的依赖兼容,推荐用这个版本(适配RN 0.55和FCM 14):buildscript { dependencies { // 其他依赖 classpath 'com.google.gms:google-services:4.2.0' } }统一Firebase/Play Services依赖版本
RN 0.55自带的Play Services版本可能和react-native-fcm的依赖冲突,在android/app/build.gradle的android块中添加强制统一版本的配置:configurations.all { resolutionStrategy { force 'com.google.android.gms:play-services-base:15.0.1' force 'com.google.firebase:firebase-core:16.0.1' } }这个版本组合和react-native-fcm 14.1.3是兼容的。
做完这些步骤后,重新运行react-native run-android应该就能正常构建了。
内容的提问来源于stack exchange,提问作者Thai Ha
相关产品推荐
相关产品推荐

