求助:Ionic Cordova项目Gradle构建遇Crashlytics插件应用错误
Hey there, I’ve run into this exact issue before with cordova-fabric-plugin—let’s break down how to fix it. The error is crystal clear: the io.fabric plugin is being loaded before the Android Gradle plugin (com.android.application), which Crashlytics depends on to function properly. Here’s what you can do to resolve this:
Step 1: Verify Gradle Plugin Order
First, head to your project’s platforms/android/build.gradle file. Look for the lines where plugins are applied. The correct order must be:
apply plugin: 'com.android.application' apply plugin: 'io.fabric'
If you see io.fabric listed before com.android.application, that’s the root cause. Move the io.fabric line below the Android plugin line and save the file.
Step 2: Reinstall the Cordova Fabric Plugin
Sometimes the plugin injects its Gradle scripts in the wrong order during installation. Try removing and re-adding the plugin to fix this automatically:
# Remove the plugin cordova plugin remove cordova-fabric-plugin # Reinstall it cordova plugin add cordova-fabric-plugin
After reinstalling, double-check the build.gradle file to confirm the plugin order is now correct.
Step 3: Ensure Gradle & Android SDK Compatibility
Older Gradle versions might not handle plugin ordering correctly, or could be incompatible with the fabric plugin. Check your Gradle wrapper version in platforms/android/gradle/wrapper/gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
Make sure this version matches the requirements of your Android plugin (you can check the Android plugin version in build.gradle under dependencies for com.android.tools.build:gradle). If needed, update the Gradle version to a compatible one.
Step 4: Clean & Rebuild Your Project
After making any changes, clean your project to clear cached build files, then rebuild:
# Clean the Android project ionic cordova clean android # Rebuild ionic cordova build android
That should resolve the plugin ordering issue and get your build working again. The key here is ensuring Crashlytics (via the fabric plugin) always loads after the Android plugin—Crashlytics needs Android’s build tools to be initialized first.
内容的提问来源于stack exchange,提问作者Dhaval Jivani

