You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

构建失败:无法找到com.getcapacitor:capacitor-android:7.1.0求解决方案

解决Capacitor Android依赖解析失败问题

问题根源分析

从错误日志和依赖配置来看,核心问题有两个:

  • 重复声明了Capacitor Android依赖:同时使用远程Maven依赖和本地模块依赖,导致Gradle解析时版本冲突
  • 本地模块capacitor-android的版本与你声明的7.1.0不匹配,Gradle实际在搜索7.0.0版本的资源

分步解决方法

1. 清理重复的依赖声明

打开app/build.gradle的dependencies块,删除其中的本地模块依赖,保留远程Maven依赖(或者反过来,确保只保留一种依赖方式):

修改后的dependencies配置:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "androidx.appcompat:appcompat:1.7.0"
    implementation "androidx.coordinatorlayout:coordinatorlayout:1.2.0"
    implementation "androidx.core:core-splashscreen:1.0.1"
    // 只保留远程Maven依赖,删除本地project依赖
    implementation 'com.getcapacitor:capacitor-android:7.1.0'
    implementation project(':capacitor-cordova-android-plugins')
    implementation project(':capacitor-local-notifications')
    testImplementation "junit:junit:4.13.2"
    androidTestImplementation "androidx.test.ext:junit:1.2.1"
    androidTestImplementation "androidx.test.espresso:espresso-core:3.6.1"
}

2. 同步Gradle并清理缓存

  • 在Android Studio中点击File > Sync Project with Gradle Files
  • 执行清理缓存操作:File > Invalidate Caches... > 勾选"Invalidate and Restart"
  • 或者在终端执行命令:
    ./gradlew clean build --refresh-dependencies
    

3. 若坚持使用本地模块依赖的处理方式

如果你需要使用本地的capacitor-android模块,确保:

  • 本地模块的版本确实是7.1.0(检查模块内的build.gradle文件中的version字段)
  • 删除远程Maven依赖声明,只保留implementation project(':capacitor-android')
  • 确认本地模块已正确导入到项目中,没有路径错误

4. 降级到5.0.0的正确操作

如果要降级到5.0.0,需要同步更新所有相关依赖:

  • 修改app/build.gradle中的依赖版本为com.getcapacitor:capacitor-android:5.0.0
  • 检查capacitor-local-notifications等插件的版本是否与Capacitor 5.x兼容(插件版本需匹配主框架版本)
  • 同步Gradle并清理缓存

验证步骤

完成上述操作后,重新执行构建,检查是否还存在依赖解析错误。如果问题仍然存在,检查:

  • 网络连接是否正常,确保能访问Maven Central和Google仓库
  • 项目根目录的build.gradle中是否正确配置了google()和mavenCentral()仓库

内容的提问来源于stack exchange,提问作者You Hur

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 09:47:47