使用Ionic Cordova构建Android APK时Firebase Crashlytics报错如何解决?
修复Ionic Cordova Android构建时的Crashlytics Gradle错误
问题场景
执行构建命令:
ionic cordova build android
出现以下错误:
- What went wrong:
A problem was found with the configuration of task ':app:injectCrashlyticsMappingFileIdDebug' (type 'InjectMappingFileIdTask').
In plugin 'com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsPlugin' type 'com.google.firebase.crashlytics.buildtools.gradle.tasks.InjectMappingFileIdTask' field 'resourceFile' without corresponding getter has been annotated with @OutputFile.
Reason: Annotations on fields are only used if there's a corresponding getter for the field.
Possible solutions:
- Add a getter for field 'resourceFile'.
- Remove the annotations on 'resourceFile'.
使用的依赖版本:
"java": "11.0.17" "gradle": "7.4.2" "@angular/cli": "~10.0.5" "@ionic/angular": "^5.3.5" "cordova-android": "10.1.2"
修复步骤
该错误由Firebase Crashlytics Gradle插件与当前Gradle版本不兼容导致,可通过以下方式解决:
方法一:升级Cordova Crashlytics插件
- 卸载旧插件:
ionic cordova plugin remove cordova-plugin-firebase-crashlytics npm uninstall @ionic-native/firebase-crashlytics
- 安装最新兼容版本:
npm install @ionic-native/firebase-crashlytics@latest ionic cordova plugin add cordova-plugin-firebase-crashlytics@latest
方法二:手动升级Crashlytics Gradle插件版本
- 打开
platforms/android/build.gradle,找到Crashlytics插件依赖,将版本替换为2.9.2及以上:
dependencies { classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2' }
- 清理缓存并重新构建:
ionic cordova clean android ionic cordova build android
方法三:降级Gradle版本
若前两种方法无效,可将Gradle降级至与cordova-android 10.1.2更匹配的7.0.x版本:
- 修改
platforms/android/gradle/wrapper/gradle-wrapper.properties中的distributionUrl:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
- 清理缓存后重新执行构建命令。
内容的提问来源于stack exchange,提问作者Shah Newaj Rabbi Shishir
相关产品推荐
相关产品推荐

