当前位置:   article > 正文

Flutter和Android中覆盖gradle中的repositories仓库地址_the server may not support the client's requested

the server may not support the client's requested tls protocol versions: (tl

覆盖Android三方库的仓库地址

问题场景

flutter中使用了一个定位权限库location_permissions,运行发现报以下错误。

* What went wrong:
A problem occurred configuring project ':location_permissions'.
> Could not resolve all artifacts for configuration ':location_permissions:classpath'.
   > Could not resolve org.ow2.asm:asm-util:6.0.
     Required by:
         project :location_permissions > com.android.tools.build:gradle:3.5.0
         project :location_permissions > com.android.tools.build:gradle:3.5.0 > com.android.tools.build:builder:3.5.0
         project :location_permissions > com.android.tools.build:gradle:3.5.0 > com.android.tools.build.jetifier:jetifier-processor:1.0.0-beta04
      > Could not resolve org.ow2.asm:asm-util:6.0.
         > Could not get resource 'https://jcenter.bintray.com/org/ow2/asm/asm-util/6.0/asm-util-6.0.pom'.
            > Could not HEAD 'https://jcenter.bintray.com/org/ow2/asm/asm-util/6.0/asm-util-6.0.pom'.
               > The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/7.2/userguide/build_environment.html#gradle_system_properties
                  > Remote host terminated the handshake
> Failed to notify project evaluation listener.
   > Could not get unknown property 'android' for project ':location_permissions' of type org.gradle.api.Project.
   > Could not get unknown property 'android' for project ':location_permissions' of type org.gradle.api.Project.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

问题分析

根据错误提示,是这个库依赖了其他三方库,从jcenter仓库下载失败了。
但是已经在android中替换了默认的jcenter仓库和maven仓库,为什么还会从jcenter下载呢。

我们打开的location_permissions的Github仓库,打开android目录下的build.gradle
在这里插入图片描述
看到这里就明白了,原来插件的android配置使用了jencter仓库,所以和插件有关的依赖都会从jencter里面下载。

解决方案

接下来我们来覆盖掉三方库中的repositories引用。
打开settings.gradle.
添加以下内容

dependencyResolutionManagement {
  repositories {
        maven {
            url 'https://maven.aliyun.com/repository/public/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/central/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/google/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/gradle-plugin/'
        }
  }
  repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

打开项目根目录的build.gradle

buildscript {
    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/public/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/central/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/google/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/gradle-plugin/'
        }
    }
	......
}

allprojects {
    buildscript {
	    repositories {
            maven {
                url 'https://maven.aliyun.com/repository/public/'
            }
            maven {
                url 'https://maven.aliyun.com/repository/central/'
            }
            maven {
                url 'https://maven.aliyun.com/repository/google/'
            }
            maven {
                url 'https://maven.aliyun.com/repository/gradle-plugin/'
            }
	    }
	}
    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/public/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/central/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/google/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/gradle-plugin/'
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50

再次运行,三方库中的依赖就能正常下载了,不会报下载失败的错误。

替换flutter sdk的repository

问题场景

再次运行,还是发现以下错误

* Where:
Build file '/Users/ado/Developer/project/x_creator/android/app/build.gradle' line: 33

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not resolve all artifacts for configuration 'classpath'.
   > Could not resolve com.google.flatbuffers:flatbuffers-java:1.12.0.
     Required by:
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0
      > Could not resolve com.google.flatbuffers:flatbuffers-java:1.12.0.
         > Could not get resource 'https://repo.maven.apache.org/maven2/com/google/flatbuffers/flatbuffers-java/1.12.0/flatbuffers-java-1.12.0.pom'.
            > Could not HEAD 'https://repo.maven.apache.org/maven2/com/google/flatbuffers/flatbuffers-java/1.12.0/flatbuffers-java-1.12.0.pom'.
               > The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/7.2/userguide/build_environment.html#gradle_system_properties
                  > Remote host terminated the handshake
   > Could not resolve org.tensorflow:tensorflow-lite-metadata:0.1.0-rc1.
     Required by:
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0
      > Could not resolve org.tensorflow:tensorflow-lite-metadata:0.1.0-rc1.
         > Could not get resource 'https://repo.maven.apache.org/maven2/org/tensorflow/tensorflow-lite-metadata/0.1.0-rc1/tensorflow-lite-metadata-0.1.0-rc1.pom'.
            > Could not GET 'https://repo.maven.apache.org/maven2/org/tensorflow/tensorflow-lite-metadata/0.1.0-rc1/tensorflow-lite-metadata-0.1.0-rc1.pom'.
               > The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/7.2/userguide/build_environment.html#gradle_system_properties
                  > Remote host terminated the handshake

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

问题分析

根据错误提示,找到app/build.gradle,在第33行发现以下引用。
Android端run或者compile时,会调用flutter sdk中的gradle仓库配置去下载对应的依赖。
在这里插入图片描述

然后我们根据这个地址去flutter sdk的对应目录下的flutter.gradle,发现了以下仓库配置。刚好对应了上面报错信息中的gradle版本号4.1.0。

解决方案

我们只需要把google和mavenCentral()换成国内的仓库镜像即可。

buildscript {
    repositories {
        //google()
        //mavenCentral()
        maven {
            url 'https://maven.aliyun.com/repository/public/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/central/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/google/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/gradle-plugin/'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

参考:Cannot override Gradle repositories in transitive plugin dependencies

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

闽ICP备14008679号