时隔数年回到Android项目,遭遇无法找到android-maven-gradle-plugin:2.1错误
问题
时隔数年重新回到我的Android项目开展开发工作时,遇到了错误:Could not find com.github.dcendents:android-maven-gradle-plugin:2.1。
项目根目录build.gradle文件内容:
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext.kotlin_version = '1.6.0' repositories { google() } dependencies { classpath 'com.android.tools.build:gradle:4.2.1' //classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' classpath "com.github.dcendents:android-maven-gradle-plugin:2.1" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() maven { url 'https://jitpack.io' } } } task clean(type: Delete) { delete rootProject.buildDir }
错误输出信息:
> Could not resolve all files for configuration ':classpath'. > Could not find com.github.dcendents:android-maven-gradle-plugin:2.1. Searched in the following locations:
解决方案
- 补充仓库源:该插件不在Google仓库中,你需要在
buildscript的repositories块里添加插件所在的仓库。修改后的代码如下:
buildscript { ext.kotlin_version = '1.6.0' repositories { google() mavenCentral() maven { url 'https://jitpack.io' } } dependencies { classpath 'com.android.tools.build:gradle:4.2.1' classpath "com.github.dcendents:android-maven-gradle-plugin:2.1" } }
- 检查版本兼容性:如果补充仓库后仍报错,可尝试降级插件到1.5版本(你注释掉的那行),该版本和Gradle 4.2.1的适配性更稳定。
- 清理依赖缓存:执行命令
./gradlew clean build --refresh-dependencies,清理本地Gradle缓存并重新拉取所有依赖。
内容的提问来源于stack exchange,提问作者Adam
相关产品推荐
相关产品推荐

