AndroidStudio编译报错 Connect to repo.maven.apache.org:443

本文介绍了由于网络问题导致的Maven资源下载失败,以及Gradle插件版本7.0以上配置冲突的解决办法。通过注释settings.gradle中的dependencyResolutionManagement,并在build.gradle中添加国内开源网址,如阿里云镜像,来避免报错并加速依赖下载。同时提供了完整的settings.gradle和build.gradle文件代码示例。
摘要由CSDN通过智能技术生成

首先需要知道的是:

1.连接错误的原因是因为没有正确上网导致的maven相关的资源拉不下来,没有梯子,就使用国内的开源网址

2. gradle插件版本号在7.0之后,build.gradle和settings.gradle配置容易重复,导致报错:

Build was configured to prefer settings repositories over project repositori…

解决方案

1.把settings.gradle的dependencyResolutionManagement整体注释,settings.gradle完整代码:

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
//dependencyResolutionManagement {
//    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
//    repositories {
//        google()
        mavenCentral()
//       maven {
//            url 'https://maven.aliyun.com/repository/central/'
//       }
//    }
//}
rootProject.name = "xxx"
include ':app'
include ':aidlaar'

2.在build.gradle中添加别的开源网址,完整代码:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.4"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter() // Warning: this repository is going to shut down soon

        //添加各种源
        maven {
            url 'https://maven.aliyun.com/repository/central/'
        }
        maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
        maven {
            url "https://jitpack.io"
        }
        maven {
            url "https://dl.bintray.com/lukaville/maven"
        }
        maven {
            url "https://maven.google.com/"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值