AndroidStudio升级报错Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve c

近日升级AS到3.2.1版本,新建工程时报错:


 

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.3.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.test:runner:1.0.2.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.test.espresso:espresso-core:3.0.2.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.3.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.3.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve junit:junit:4.12.
Open File
Show Details
 


错误原因:项目默认配置了gradle 4.6版本,镜像服务器错误(mirrors.neusoft.edu.cn 没有提供下载服务)导致无法下载gradle-4.6-all.zip,无法完成编译。

 

解决方法1:降低gradle版本

  • 打开 gradle/wrapper/gradle-wrapper.properties,修改gradle版本为本地已下载版本。如gradle-4.4-all.zip

distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

记得同时修改build.gradle内容:3.1.0

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'    
}

解决方法2:更新到最新版本

  • 不使用镜像地址下载gradle-4.6-all.zip,因为镜像地址连接失败,所以把它拿掉。
    找到
    /Users/lvxiangan/.gradle文件夹,打开gradle.properties

     

    ## For more details on how to configure your build environment visit
    # http://www.gradle.org/docs/current/userguide/build_environment.html
    #
    # Specifies the JVM arguments used for the daemon process.
    # The setting is particularly useful for tweaking memory settings.
    # Default value: -Xmx1024m -XX:MaxPermSize=256m
    # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
    #
    # When configured, Gradle will run in incubating parallel mode.
    # This option should only be used with decoupled projects. More details, visit
    # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
    # org.gradle.parallel=true
    #Thu Dec 06 23:52:05 CST 2018
    使用#号注释掉以下4行
    systemProp.http.proxyHost=mirrors.neusoft.edu.cn
    systemProp.http.proxyPort=80
    systemProp.https.proxyHost=mirrors.neusoft.edu.cn
    systemProp.https.proxyPort=80

    或者删除整个文件。重启AS,可以看到正在重新下载gradle-4.6-all.zip

     
  • 如果上一步下载很慢,可以通过网盘或迅雷下载到本地,从本地直接加载。

    下载好复制到 /Users/lvxiangan/.gradle/wrapper/dists/gradle-4.6-all/bcst21l2brirad8k2ben1letg 文件夹下,然后重启AS。

    注意:bcst21l2brirad8k2ben1letg 文件夹名称是由系统随机产生,请不要尝试修改它。

最后来一张成功编译图,晚安!

 

 

 

 

### Android Studio 中依赖项无法解析的解决方案 当面对 `Unable to resolve dependency for` 错误时,通常意味着构建工具未能找到所需的库文件或版本不兼容。以下是几种常见的解决办法: #### 1. 检查网络连接和仓库设置 确保拥有稳定的互联网连接,并确认项目的 Gradle 配置指向了正确的 Maven 或 JCenter 库地址[^1]。 如果使用的是较新的 Android 版本,则建议将所有的支持库替换为 AndroidX 形式的依赖声明[^3]。 ```gradle // build.gradle (Project level) allprojects { repositories { google() // 添加 Google 的官方存储库 mavenCentral() } } ``` #### 2. 更新 Gradle 和插件版本 保持使用的 Gradle 及其插件处于最新状态可以有效减少此类问题的发生概率。对于新创建的应用程序,默认情况下会采用最新的稳定版;而对于旧项目则需手动更新至更高版本[^2]。 修改根目录下的 `build.gradle` 文件来指定更现代的 Gradle Wrapper 和 Android 插件版本号: ```groovy plugins { id 'com.android.application' version '8.0.0' apply false } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() } } ``` #### 3. 清理缓存并重新同步项目 有时本地缓存可能会导致依赖关系混乱,尝试执行以下操作清除现有数据后再让 IDE 自动下载所需资源[^4]: - **File** -> **Invalidate Caches / Restart...** - 关闭应用程序后再次打开它 - 执行菜单命令 **Sync Project with Gradle Files** #### 4. 修改依赖版本范围 某些时候特定版本可能确实不存在于远程服务器上,这时应该调整依赖表达式中的版本约束条件以匹配实际存在的版本区间。 例如原先是这样的写法: ```groovy implementation 'com.android.support:design:33.+' ``` 改为具体版本号如: ```groovy implementation 'com.google.android.material:material:1.9.0' ```
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值