当前位置:   article > 正文

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

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

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

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

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

图片

图片

图片

图片

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

  1. A problem occurred configuring root project 'Packer'.
  2. > Could not resolve all dependencies for configuration ':classpath'.
  3. > 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.
  4. * Try:
  5. 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中进行如下的配置即可解决
  1. 解决方法:
  2. 只需要在C:\Users\LENOVO\.gradle\init.gradle文件中或者App项目工程的build.gradle中,使用allowInsecureProtocol属性(允许gradle使用"不安全"的仓库并且不报警告信息)
  3. allowInsecureProtocol = true

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

图片

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

图片

  1. buildscript {
  2. repositories {
  3. //ADD START
  4. maven {
  5. allowInsecureProtocol = true
  6. url 'http://maven.aliyun.com/nexus/content/groups/public/'
  7. }
  8. maven {
  9. allowInsecureProtocol = true
  10. url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
  11. }
  12. maven {
  13. allowInsecureProtocol = true
  14. url 'http://maven.aliyun.com/nexus/content/repositories/google'
  15. }
  16. maven {
  17. allowInsecureProtocol = true
  18. url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin'
  19. }
  20. //ADD END
  21. google()
  22. jcenter()
  23. }
  24. dependencies {
  25.         classpath 'com.android.tools.build:gradle:7.0.0'
  26. }
  27. }

图片

  1. allprojects {
  2. repositories {
  3. //ADD START
  4. maven {
  5. allowInsecureProtocol = true
  6. url 'http://maven.aliyun.com/nexus/content/groups/public/'
  7. }
  8. maven {
  9. allowInsecureProtocol = true
  10. url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
  11. }
  12. maven {
  13. allowInsecureProtocol = true
  14. url 'http://maven.aliyun.com/nexus/content/repositories/google'
  15. }
  16. maven {
  17. allowInsecureProtocol = true
  18. url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin'
  19. }
  20. //ADD END
  21. google()
  22. jcenter()
  23. }
  24. }
  25. task clean(type: Delete) {
  26. delete rootProject.buildDir
  27. }

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

图片

图片

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

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

第一种情况:with groovy

  1. repositories {
  2. maven {
  3. allowInsecureProtocol = true
  4. url "http://maven.aliyun.com/nexus/content/groups/public/"
  5. }
  6. maven {
  7. allowInsecureProtocol = true
  8. url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
  9. }
  10. maven {
  11. allowInsecureProtocol = true
  12. url 'http://maven.aliyun.com/nexus/content/repositories/google'
  13. }
  14. maven {
  15. allowInsecureProtocol = true
  16. url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin'
  17. }
  18. }

第二种情况:with kotlin

  1. repositories {
  2. maven {
  3. isAllowInsecureProtocol = true
  4. setUrl("http://maven.aliyun.com/nexus/content/groups/public/")
  5. }
  6. maven {
  7. isAllowInsecureProtocol = true
  8. setUrl("http://maven.aliyun.com/nexus/content/repositories/jcenter")
  9. }
  10. maven {
  11. isAllowInsecureProtocol = true
  12. setUrl("http://maven.aliyun.com/nexus/content/repositories/google")
  13. }
  14. maven {
  15. isAllowInsecureProtocol = true
  16. setUrl("http://maven.aliyun.com/nexus/content/repositories/gradle-plugin")
  17. }
  18. }

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

图片

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/795720
推荐阅读
相关标签
  

闽ICP备14008679号