Android Studio中gradle升级报gradle的仓库地址不安全警告

1.Android Studio中gradle版本升级(阿里云仓库下载源)

classpath 'com.android.tools.build:gradle:3.6.3'
升级为
classpath 'com.android.tools.build:gradle:7.0.0'
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.7-all.zip
升级为
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip

2.Android Studio报gradle的仓库地址不安全警告的错误

图片

图片

图片

图片

使用"阿里云"仓库为下载源,如果直接升级gradle版本,可能会报错(gradle的仓库地址不安全警告的错误),因为配置了除maven中央仓库之外的其他不安全的仓库(一些国内的镜像仓库,如"阿里云"镜像仓库也是不安全的),如下所示:

A problem occurred configuring root project 'Packer'.
> Could not resolve all dependencies for configuration ':classpath'.
   > Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven repository 'maven(http://maven.aliyun.com/nexus/content/groups/public/)' to redirect to a secure protocol (like HTTPS) or allow insecure protocols. See https://docs.gradle.org/7.0.2/dsl/org.gradle.api.artifacts.repositories.UrlArtifactRepository.html#org.gradle.api.artifacts.repositories.UrlArtifactRepository:allowInsecureProtocol for more details. 
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

3.使用allowInsecureProtocol属性解决gradle的仓库地址不安全警告的解决方法

gradle中有一个属性可以允许gradle使用"不安全"的仓库并且不报警告信息,该属性是allowInsecureProtocol,指定通过不安全的HTTP连接与仓库通信是否可接受,如果该属性的值设置为true,则表示接受"不安全"的仓库地址

只需要在C:\Users\LENOVO\.gradle\init.gradle文件中或者App项目工程的build.gradle中进行如下的配置即可解决
解决方法:
只需要在C:\Users\LENOVO\.gradle\init.gradle文件中或者App项目工程的build.gradle中,使用allowInsecureProtocol属性(允许gradle使用"不安全"的仓库并且不报警告信息)
allowInsecureProtocol = true

(1).C:\Users\LENOVO\.gradle\init.gradle

图片

(2).App项目工程的build.gradle

图片

buildscript {
    repositories {
        //ADD START
        maven {
            allowInsecureProtocol = true
            url 'http://maven.aliyun.com/nexus/content/groups/public/'
        }
        maven {
            allowInsecureProtocol = true
            url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
        }
        maven {
            allowInsecureProtocol = true
            url 'http://maven.aliyun.com/nexus/content/repositories/google'
        }
        maven {
            allowInsecureProtocol = true
            url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin'
        }
        //ADD END
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.0'
    }
}

图片

allprojects {
    repositories {
        //ADD START
        maven {
            allowInsecureProtocol = true
            url 'http://maven.aliyun.com/nexus/content/groups/public/'
        }
        maven {
            allowInsecureProtocol = true
            url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
        }
        maven {
            allowInsecureProtocol = true
            url 'http://maven.aliyun.com/nexus/content/repositories/google'
        }
        maven {
            allowInsecureProtocol = true
            url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin'
        }
        //ADD END
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

4.Android Studio App项目工程同步成功、App项目编译成功

图片

图片

5.Android Studio中gradle的仓库地址不安全警告通用解决方案(阿里云源)

gradle为了安全考虑,防止他人冒充目标服务器,并在资源中植入恶意代码...,所以默认禁用使用非官方的中央仓库(包括:阿里云),如果确认信任该仓库,需要显示声明信任它

第一种情况:with groovy

repositories {
    maven { 
        allowInsecureProtocol = true
        url "http://maven.aliyun.com/nexus/content/groups/public/" 
    }
    maven {
            allowInsecureProtocol = true
            url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
        }
        maven {
            allowInsecureProtocol = true
            url 'http://maven.aliyun.com/nexus/content/repositories/google'
        }
        maven {
            allowInsecureProtocol = true
            url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin'
        }
}

第二种情况:with kotlin

repositories {
     maven { 
         isAllowInsecureProtocol = true
         setUrl("http://maven.aliyun.com/nexus/content/groups/public/") 
     }
     maven { 
         isAllowInsecureProtocol = true
         setUrl("http://maven.aliyun.com/nexus/content/repositories/jcenter") 
     }
     maven { 
         isAllowInsecureProtocol = true
         setUrl("http://maven.aliyun.com/nexus/content/repositories/google") 
     }
     maven { 
         isAllowInsecureProtocol = true
         setUrl("http://maven.aliyun.com/nexus/content/repositories/gradle-plugin") 
     }
}

Android Studio gradle无法编译App的完美解决方法

图片

  • 12
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

哆啦安全

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值