学无先后,达者为师

网站首页 编程语言 正文

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

作者:会游泳的猫! 更新时间: 2022-08-30 编程语言

首先需要知道的是:

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
}

原文链接:https://blog.csdn.net/ABCDEF123236/article/details/124683545

栏目分类
最近更新