Could not find common.jar (android.arch.core:common:1.0.0)/Failed to resolve :common解决办法

本文介绍了在使用Android Studio过程中遇到的依赖问题Failed to resolve: common及其解决方案。问题表现为无法找到common.jar(android.arch.core:common:1.0.0)。文中提供了三种解决方法:更改依赖版本、添加Maven仓库地址及调整google()仓库位置。

这些天,在家里重新安装Android Studio的时候,遇到一个问题

Failed to resolve :common

有些人也有可能是这样

Could not find common.jar (android.arch.core:common:1.0.0)

但是其实他们都是一个问题,这是谷歌近期大面积出现的一个问题。

通过在网上搜索,一般的解决方案有两种

1.把build.gradle中所有的

compile 'com.android.support:appcompat-v7:26.+'

都改成

compile 'com.android.support:appcompat-v7:26.0.0'

也就是不要所有".+"这种形式的compile

不过这种方式对我无效


2.把项目的build.gradle中allprojects{}中加上

maven{url"https://maven.google.com"}

不过对我来说还是没用

因为我用的as3.1.3,已经有google()这个标签了


3.这个是对我唯一有效的方法

就是把google()标签,移动到allprojects中的最上面

这个解决办法虽然可以理解,但是确实很扯

This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry. The following AndroidX dependencies are detected: androidx.appcompat:appcompat:1.0.0, androidx.versionedparcelable:versionedparcelable:1.0.0, androidx.fragment:fragment:1.0.0, androidx.slidingpanelayout:slidingpanelayout:1.0.0, androidx.core:core:1.0.0, androidx.customview:customview:1.0.0, androidx.swiperefreshlayout:swiperefreshlayout:1.0.0, androidx.interpolator:interpolator:1.0.0, androidx.loader:loader:1.0.0, androidx.drawerlayout:drawerlayout:1.0.0, androidx.viewpager:viewpager:1.0.0, androidx.collection:collection:1.0.0, androidx.localbroadcastmanager:localbroadcastmanager:1.0.0, androidx.lifecycle:lifecycle-common:2.0.0, androidx.arch.core:core-common:2.0.0, androidx.annotation:annotation:1.0.0, androidx.lifecycle:lifecycle-livedata:2.0.0, androidx.legacy:legacy-support-core-ui:1.0.0, androidx.lifecycle:lifecycle-viewmodel:2.0.0, androidx.lifecycle:lifecycle-livedata-core:2.0.0, androidx.arch.core:core-runtime:2.0.0, androidx.legacy:legacy-support-core-utils:1.0.0, androidx.documentfile:documentfile:1.0.0, androidx.vectordrawable:vectordrawable-animated:1.0.0, androidx.cursoradapter:cursoradapter:1.0.0, androidx.vectordrawable:vectordrawable:1.0.0, androidx.lifecycle:lifecycle-runtime:2.0.0, androidx.coordinatorlayout:coordinatorlayout:1.0.0, androidx.asynclayoutinflater:asynclayoutinflater:1.0.0, androidx.print:print:1.0.0
07-03
<think>我们正在解决一个具体的依赖解析失败问题:Failed to resolve androidx.arch.core:core-compiler:2.1.0 根据用户提供的引用,他们使用了android.arch.lifecycle:extensions:1.1.1等旧版Android Architecture Components库(引用[1]),而问题中出现的依赖是androidx.arch.core:core-compiler,这是一个AndroidX库。 问题分析: 1. 用户可能正在迁移项目到AndroidX,或者混合使用了Android Support Library和AndroidX库。 2. 错误信息表明Gradle无法找到androidx.arch.core:core-compiler:2.1.0这个特定版本。 解决方案: 步骤1:检查仓库设置 确保在项目的build.gradle(顶级)中包含了Google的Maven仓库和jcenter(或mavenCentral),因为AndroidX库通常托管在Google Maven仓库。 步骤2:检查依赖版本 用户使用的android.arch.lifecycle:extensions:1.1.1是旧的支持库版本,而core-compiler:2.1.0AndroidX版本。这两个库可能不兼容。 步骤3:解决版本冲突 可能由于其他依赖传递引入了core-compiler:2.1.0,但该版本在仓库中不存在。我们可以尝试: a. 升级整个项目到一致的AndroidX版本 b. 显式指定core-compiler的可用版本 已知:androidx.arch.core:core-compiler库在2.1.0版本可能不存在,或者已经被其他版本替代。 步骤4:检查可用版本 访问https://maven.google.com/web/index.html 搜索core-compiler,我们发现: - 该库的全称可能是androidx.arch.core:core-common(用于注解处理)或androidx.arch.core:core-runtime(运行时库) - 实际上,core-compiler这个artifactId并不存在,可能是用户误写或者某个库的错误传递。 根据错误信息,我们怀疑是某个库依赖了core-compiler,但该库不存在。因此,我们需要找出是哪个依赖引入了core-compiler。 步骤5:使用Gradle命令找出依赖关系 在终端运行: ./gradlew :app:dependencies --configuration debugCompileClasspath 或者(如果模块名不是app,则替换) ./gradlew app:dependencies 查看输出,搜索core-compiler,找到引入它的库。 步骤6:解决方案 a. 如果确实有库依赖了core-compiler,但该库不存在,我们可以排除这个传递依赖: implementation("some.library") { exclude group: 'androidx.arch.core', module: 'core-compiler' } b. 升级相关依赖到最新版本,避免使用旧版(特别是android.arch.*)库。 根据引用[1]中用户使用的旧版导航库(1.0.0-alpha07)和Lifecycle扩展(1.1.1),建议升级到AndroidX的稳定版本。 步骤7:迁移到AndroidX - 使用Android Studio的迁移工具:Refactor > Migrate to AndroidX - 在gradle.properties中设置: android.useAndroidX=true android.enableJetifier=true 步骤8:更新依赖版本 - 将Lifecycle依赖替换为AndroidX版本: def lifecycle_version = "2.5.1" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version" // 等等 - 导航库更新(引用[1]中的导航库): def nav_version = "2.5.3" implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" implementation "androidx.navigation:navigation-ui-ktx:$nav_version" 步骤9:如果问题仍然存在,强制指定core库的版本(如果确实需要) 但注意:core-compiler可能是一个不存在的库,我们可能需要排除它或者忽略。 另一种可能:core-compiler可能是annotationProcessor配置的,而不是implementation。检查是否应该使用annotationProcessor。 但是,根据错误信息,我们通常不会在编译时使用core-compiler(除非是注解处理器)。所以,检查是否有annotationProcessor引入了它。 如果错误是关于注解处理器的,那么应该这样排除: annotationProcessor("some.library") { exclude group: 'androidx.arch.core', module: 'core-compiler' } 总结步骤: 1. 确保仓库设置正确。 2. 迁移到AndroidX并更新所有依赖到AndroidX稳定版本。 3. 使用Gradle命令找出引入core-compiler的依赖,然后排除它。 4. 如果排除后影响功能,考虑升级引入该传递依赖的库。 注意:core-compiler:2.1.0这个库在Google Maven仓库中不存在,因此很可能是某个库的错误传递依赖。排除它是安全的。 具体操作示例(如果找到是libXXX引入了core-compiler): implementation('libXXX') { exclude group: 'androidx.arch.core', module: 'core-compiler' } 如果找不到,但错误仍然存在,可以在所有配置中全局排除: configurations { all { exclude group: 'androidx.arch.core', module: 'core-compiler' } } 最后,如果问题解决,建议更新所有库到最新稳定版,以避免类似问题。 根据引用[2]中提到的Lifecycle源码解析,我们知道Lifecycle库在AndroidX中已经成熟,因此升级是推荐的。 因此,我们优先推荐迁移到AndroidX并更新依赖版本,这样很可能就解决了问题。</think>### 解决 Android 依赖解析失败:`Failed to resolve androidx.arch.core:core-compiler:2.1.0` #### 问题原因分析 1. **库不存在或版本错误** `androidx.arch.core:core-compiler:2.1.0` 是一个**不存在的依赖项**: - `core-compiler` 不是 AndroidX Arch 组件的有效模块名 - 正确模块应为 `core-common` 或 `core-runtime` [^2] - 最新稳定版本为 `2.2.0`(截至2023年) 2. **依赖冲突** 旧版 Lifecycle 扩展(如你使用的 `android.arch.lifecycle:extensions:1.1.1`)可能尝试拉取不兼容的 Arch 组件版本 [^1] 3. **仓库配置缺失** 项目可能未正确配置 Google Maven 仓库(该库仅在此托管) --- #### 解决方案步骤 ##### 1. 修正依赖声明(关键步骤) ```gradle // build.gradle (app 模块) dependencies { // 替换为正确的 Arch Core 依赖 implementation "androidx.arch.core:core-common:2.2.0" implementation "androidx.arch.core:core-runtime:2.2.0" // 升级 Lifecycle 到 AndroidX 版本(推荐) def lifecycle_version = "2.6.1" implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version" implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version" // 移除旧版支持库依赖(如引用[1]中的) // implementation 'android.arch.lifecycle:extensions:1.1.1' } ``` ##### 2. 检查仓库配置 确保项目级 `build.gradle` 包含 Google 仓库: ```gradle // build.gradle (项目级) allprojects { repositories { google() // 必须存在 mavenCentral() } } ``` ##### 3. 解决依赖冲突 在终端运行依赖分析命令: ```bash ./gradlew :app:dependencies --configuration debugCompileClasspath ``` 检查输出中是否存在版本冲突,若有则强制指定版本: ```gradle configurations.all { resolutionStrategy.force 'androidx.arch.core:core-common:2.2.0' } ``` ##### 4. 清理构建缓存 ```bash ./gradlew cleanBuildCache && ./gradlew --stop rm -rf ~/.gradle/caches/ # 清除全局Gradle缓存 ``` --- #### 完整配置示例 ```gradle // build.gradle (app模块) android { // 确保使用 AndroidX compileSdk 34 defaultConfig { //... } } dependencies { // AndroidX Arch 组件 implementation "androidx.arch.core:core-common:2.2.0" implementation "androidx.arch.core:core-runtime:2.2.0" // 新版 Lifecycle implementation "androidx.lifecycle:lifecycle-extensions:2.6.1" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1" // 导航组件 (升级自引用[1]的 alpha 版) implementation "androidx.navigation:navigation-fragment:2.7.1" implementation "androidx.navigation:navigation-ui:2.7.1" } ``` --- #### 技术原理说明 1. **模块名变更** AndroidX 将原 `android.arch` 包重构为: - `core-common`:通用工具类 - `core-runtime`:生命周期运行时 - `core-testing`:测试工具 2. **版本兼容性** Lifecycle 2.4+ 要求使用 AndroidX 依赖,旧版 `android.arch.*` 会导致依赖地狱[^2] 3. **构建缓存机制** Gradle 会缓存错误依赖信息,需彻底清理才能生效 > **验证方法**:访问 [Google Maven 仓库](https://maven.google.com/web/index.html) 搜索 `androidx.arch.core` 查看可用版本
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值