赞
踩
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")
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。