AS解决阿里云的http或https的问题,Using insecure protocols with repositories, without explicit opt-in,

这篇博客分享了解决Gradle构建时由于访问HTTPS仓库失败的问题,通过在C盘Gradle初始化文件及项目根目录的build.gradle中添加配置,允许不安全协议并替换为阿里云的镜像源。步骤包括在init.gradle中添加allowInsecureProtocol选项,以及在项目build.gradle中修改相应仓库URL。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先说表达一下,真的是太恶心了,网上说的很多的方法都是不靠谱的。

下面我展示我的绝招。

1、在C:\Users\XXX\.gradle的init.gradle文件中添加一行代码:allowInsecureProtocol = true(切记有等于号)

allprojects{
    repositories {
        def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
        def ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
        all { ArtifactRepository repo ->
            if(repo instanceof MavenArtifactRepository){
                def url = repo.url.toString()
                if (url.startsWith('https://repo1.maven.org/maven2')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
                    remove repo
                }
                if (url.startsWith('https://jcenter.bintray.com/')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
                    remove repo
                }
            }
        }
        maven {
		    allowInsecureProtocol = true  //就是这一行
            url ALIYUN_REPOSITORY_URL
            url ALIYUN_JCENTER_URL
        }
    }
}

2、在项目的根目标下的build.gradle中修改:allowInsecureProtocol true(切记无等于号),此外将http改为https

buildscript {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven {
            allowInsecureProtocol true //就是这一行
            url "https://jitpack.io"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven {
            allowInsecureProtocol true //就是这一行
            url 'https://maven.aliyun.com/nexus/content/groups/public/'
        }

    }
}


然后就是好好的等待问题重新构建

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值