当前位置:   article > 正文

首次安装Android Studio,gradle7.x下载慢的问题_still waiting for package manifests to be fetched

still waiting for package manifests to be fetched remotely.

下载了最新的Android Studio,第一次运行项目时gradle下载了很慢很慢,想换成阿里源,但是因为gradle是7.X,所以各种报错,网上的方法基本都是针对6.X的,大概根据网上的原理做了几次修改也最终解决了,记录一下。

1. 阿里源修改

根目录下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'
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

网上的教程基本上也加了下面一个片段

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
        maven { url "https://jitpack.io" }
        google()
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

但是最新版本中会报错,删掉就行

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'
  • 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

这样就配置完成了

2. 关于SSL的问题

设置阿里源时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}
  • 1

参考stackoverflowhttps://stackoverflow.com/questions/68585885/allow-insecure-protocols-android-gradle


这么点问题调试了好久。。。。

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

闽ICP备14008679号