赞
踩
下载了最新的Android Studio,第一次运行项目时gradle下载了很慢很慢,想换成阿里源,但是因为gradle是7.X,所以各种报错,网上的方法基本都是针对6.X的,大概根据网上的原理做了几次修改也最终解决了,记录一下。
根目录下setting.gradle和build.gradle都要修改。
build.gradle里加入以下代码
buildscript {
repositories {
maven{url 'http://maven.aliyun.com/nexus/content/groups/public/';allowInsecureProtocol = true}
maven { url "https://jitpack.io" }
//maven { url 'http://repo1.maven.org/maven2';allowInsecureProtocol = true}
google()
// jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
}
}
网上的教程基本上也加了下面一个片段
allprojects {
repositories {
jcenter()
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
maven { url "https://jitpack.io" }
google()
}
}
但是最新版本中会报错,删掉就行
Build was configured to prefer settings repositories over project repositories but repository ‘maven’ was added by build file ‘build.gradle’……
这个网站分析的挺好:https://testfairy.com/blog/how-to-prefer-settings-gradle-repositories-over-build-gradle/
然后是修改setting.gradle
pluginManagement { repositories { maven { url "http://maven.aliyun.com/nexus/content/groups/public/" ;allowInsecureProtocol = true } gradlePluginPortal() google() mavenCentral() maven { url "https://jitpack.io" } //maven { url 'http://repo1.maven.org/maven2';allowInsecureProtocol = true} } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { maven { url "http://maven.aliyun.com/nexus/content/groups/public/" ;allowInsecureProtocol = true} google() mavenCentral() maven { url "https://jitpack.io" } } } rootProject.name = "My Application" include ':app'
这样就配置完成了
设置阿里源时gradle7.x对于http的地址会报错,它默认不允许使用不安全的地址,但是如果只把http改成https,我访问时就超时了,不断弹出
Still waiting for package manifests to be fetched remotely.
所以使用http的时候要在后面加上allowInsecureProtocol = true
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" ;allowInsecureProtocol = true}
参考stackoverflow:https://stackoverflow.com/questions/68585885/allow-insecure-protocols-android-gradle
这么点问题调试了好久。。。。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。