如何修复Ionic构建Android时的‘Could not find android-maven-gradle-plugin.jar’错误?
Hey there, let’s tackle that frustrating error you’re seeing when building your Ionic Android project. I’ve helped a few developers work through this exact issue, and these are the most effective solutions to get your build running smoothly again:
1. Verify and Update Gradle Dependencies & Repositories
First, double-check your project’s Gradle configuration to ensure the plugin is being pulled correctly:
- Navigate to your Ionic project’s root folder, open
android/build.gradle, and locate thebuildscriptblock. - In the
dependenciessection, confirm you have a valid reference to the plugin, like:
If you’re using an older version, try updating toclasspath 'com.github.dcendents:android-maven-gradle-plugin:2.1'2.1(it’s widely compatible with most Ionic/Cordova setups). - Make sure the
buildscript>repositoriessection includesmavenCentral()orgoogle()—this is where the plugin is hosted, so missing these will prevent Gradle from finding the jar.
2. Clear Gradle’s Cache
Corrupted or outdated cache files often cause dependency lookup failures. Here’s how to fix it:
- Run this command in your project’s
androiddirectory to clean and refresh dependencies:# macOS/Linux ./gradlew clean build --refresh-dependencies # Windows gradlew.bat clean build --refresh-dependencies - If that doesn’t work, manually delete Gradle’s cache directory:
- Windows:
C:\Users\<YourUsername>\.gradle\caches - macOS/Linux:
~/.gradle/caches
After deleting, restart your IDE and try building again.
- Windows:
3. Check for Plugin Compatibility Issues
Old or poorly maintained Cordova plugins might be pulling in conflicting versions of the maven plugin:
- Run
ionic cordova plugin listto see all installed plugins. Look for any plugins that haven’t been updated in a year or more—these are prime suspects. - Update suspicious plugins with:
If updating doesn’t help, try uninstalling and re-installing the plugin to get the latest compatible version.ionic cordova plugin update <PluginName>
4. Downgrade Gradle to a Compatible Version
Newer Gradle versions can sometimes break compatibility with older plugins like android-maven-gradle-plugin. Try rolling back to a stable, compatible version:
- Open
android/gradle/wrapper/gradle-wrapper.propertiesand modify thedistributionUrlline to use a compatible Gradle version, e.g.:
This version works reliably with the 2.1 release of the maven plugin.distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip - Save the file and re-run your build command.
Bonus Tip
If none of the above works, create a fresh blank Ionic project and attempt to build it for Android. If the fresh build works, the issue is likely with your original project’s configuration—you can then gradually migrate your code, assets, and plugins to the new project to isolate the problem.
内容的提问来源于stack exchange,提问作者LulzSec

