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

Android Studio 2022.3.1默认Kotlin项目构建失败求助

Android Studio默认Kotlin项目构建失败:依赖无法解析问题解决

问题描述

刚接触Android Studio,运行默认Kotlin项目时构建失败,出现约21个错误,均源于androidx.compose.material:material:1.4.0或androidx.concurrent:concurrent-futures:1.1.0依赖无法解析。点击错误中的链接可下载对应文件,但不知如何处理。

错误日志

> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Failed to transform material-1.4.0.aar (androidx.compose.material:material:1.4.0) to match attributes {artifactType=android-aar-metadata, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Could not find material-1.4.0.aar (androidx.compose.material:material:1.4.0).
        Searched in the following locations:
            https://dl.google.com/dl/android/maven2/androidx/compose/material/material/1.4.0/material-1.4.0.aar
7: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:mergeDebugNativeLibs'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Failed to transform material-1.4.0.aar (androidx.compose.material:material:1.4.0) to match attributes {artifactType=android-jni, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Could not find material-1.4.0.aar (androidx.compose.material:material:1.4.0).
        Searched in the following locations:
            https://dl.google.com/dl/android/maven2/androidx/compose/material/material/1.4.0/material-1.4.0.aar
   > Failed to transform concurrent-futures-1.1.0.jar (androidx.concurrent:concurrent-futures:1.1.0) to match attributes {artifactType=android-jni, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.jvm.version=7, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Could not find concurrent-futures-1.1.0.jar (androidx.concurrent:concurrent-futures:1.1.0).
        Searched in the following locations:
            https://dl.google.com/dl/android/maven2/androidx/concurrent/concurrent-futures/1.1.0/concurrent-futures-1.1.0.jar

已尝试但无效的方法

  • 重新安装Android Studio
  • 将Gradle JDK从jbr-17切换至Oracle Open JDK 21
  • 更新Kotlin编译器至最新版本
  • 执行Invalidate Caches操作
  • 将Android SDK目标版本和编译版本改为34
  • 修改JAVA_HOME路径(后因出现其他错误改回)

解决方案

方法一:手动放置下载的依赖文件到本地仓库

  1. 从错误日志中的链接下载material-1.4.0.aar和concurrent-futures-1.1.0.jar文件
  2. 找到本地Gradle仓库路径:Windows系统为C:\Users\你的用户名\.gradle\caches\modules-2\files-2.1,Mac/Linux为~/.gradle/caches/modules-2/files-2.1
  3. 按依赖包路径结构创建对应文件夹:
    • 对于androidx.compose.material:material:1.4.0,创建路径androidx/compose/material/material/1.4.0,将下载的aar文件放入该文件夹
    • 对于androidx.concurrent:concurrent-futures:1.1.0,创建路径androidx/concurrent/concurrent-futures/1.1.0,将下载的jar文件放入该文件夹
  4. 重启Android Studio,点击「Sync Project with Gradle Files」后重新构建项目

方法二:配置国内镜像源解决网络问题

如果无法正常访问Google Maven仓库,可在项目根目录的settings.gradle文件中添加国内镜像源:

pluginManagement {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        google()
        mavenCentral()
    }
}

同步Gradle后重新构建项目

方法三:调整依赖版本

打开app模块下的build.gradle文件,修改依赖版本为兼容的更新版本:

// 修改Compose Material版本
implementation "androidx.compose.material:material:1.5.0"
// 若有显式声明concurrent-futures依赖,修改版本
implementation "androidx.concurrent:concurrent-futures:1.2.0"

同步Gradle后重新构建项目

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 14:34:56