赞
踩
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.
根据错误提示,是这个库依赖了其他三方库,从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) }
打开项目根目录的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/' } } }
再次运行,三方库中的依赖就能正常下载了,不会报下载失败的错误。
再次运行,还是发现以下错误
* 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
根据错误提示,找到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' } }
参考:Cannot override Gradle repositories in transitive plugin dependencies
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。