Java Gradle 构建错误:无法从 https://repo1.maven.org/maven2/io/fabric/tools/gradle/maven-metadata.xml 加载 Maven 元数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29119716/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 07:24:02  来源:igfitidea点击:

Gradle Build Error: Unable to load Maven meta-data from https://repo1.maven.org/maven2/io/fabric/tools/gradle/maven-metadata.xml

javaandroidmavenandroid-studioandroid-gradle-plugin

提问by user2678020

I am getting a gradle build error in Android studio as below:

我在 Android Studio 中收到一个 gradle 构建错误,如下所示:

    Error:A problem occurred configuring project ':MyApp'.
    Could not resolve all dependencies for configuration ':MyApp:classpath'.
    Could not resolve io.fabric.tools:gradle:1.+.     
Required by:
    sw-android:MyApp:unspecified
    Failed to list versions for io.fabric.tools:gradle.
        Unable to load Maven meta-data from     
    https://repo1.maven.org/maven2/io/fabric/tools/gradle/maven-metadata.xml.
     Could not GET 'https://repo1.maven.org/maven2/io/fabric/tools/gradle/maven-metadata.xml'.
    peer not authenticated
        Failed to list versions for io.fabric.tools:gradle.
        Unable to load Maven meta-data from  
        http://maven.fabric.io/public/io/fabric/tools/gradle/maven-metadata.xml.
        Could not GET http://maven.fabric.io/public/io/fabric/tools/gradle/maven-metadata.xml'.
        peer not authenticated

I found that "https" Tag is not working to download the Maven URL so I changed the https to http in my build.gradle file. Also I checked all the gradle settings and manually modify the other.xml file in the path C:\Users\Ashfaque1.AndroidStudio\config\options\ but still it is taking the https://repo1.maven.org/maven2/io/fabric/tools/gradle/maven-metadata.xml. Also once I am hitting this link to the browser I am getting the 404 exception but the 2nd URL in Error http://maven.fabric.io/public/io/fabric/tools/gradle/maven-metadata.xml, I am able to hit successfully and downloading the Metadata file correctly in my system. Not able to understand what is the problem, where I need to change the settings so that metadata file will be downloaded. Please suggest if I need to change any settings or from where it is taking this URL https://repo1.maven.org/maven2//io/fabric/tools/gradle/maven-metadata.xml

我发现“https”标签无法下载 Maven URL,因此我在 build.gradle 文件中将 https 更改为 http。此外,我检查了所有 gradle 设置并手动修改路径 C:\Users\Ashfaque1.AndroidStudio\config\options\ 中的 other.xml 文件,但它仍然采用https://repo1.maven.org/maven2/io /fabric/tools/gradle/maven-metadata.xml。此外,一旦我点击此链接到浏览器,我就会收到 404 异常,但错误中的第二个 URL http://maven.fabric.io/public/io/fabric/tools/gradle/maven-metadata.xml,我能够成功命中并在我的系统中正确下载元数据文件。无法理解是什么问题,我需要更改设置以便下载元数据文件。请建议我是否需要更改任何设置或从何处获取此 URL https://repo1.maven.org/maven2//io/fabric/tools/gradle/maven-metadata.xml

My build.gradle file is as below:

我的 build.gradle 文件如下:

    apply plugin: 'com.android.application'
    apply plugin: 'io.fabric'

    buildscript {
    repositories {
        mavenCentral()
        maven { url 'http://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
        classpath 'io.fabric.tools:gradle:1.+'
    }
    }

    repositories {
        mavenCentral()
        maven { url 'http://maven.fabric.io/public' }
    }

    dependencies {
    compile 'com.android.support:multidex:1.0.0'
    compile fileTree(dir: 'libs',include: '*.jar')
    compile project(':DeviceService')
    compile project(':RatioCommon')
    compile project(':SlidingMenu:library')   
    compile project(':SmartViewLibrary:SmartView')
    compile project(':SmartViewLibrary:OpenAccess')
    compile('com.crashlytics.sdk.android:crashlytics:2.2.0@aar') {
        transitive = true;
    }
   }
   compileSdkVersion 21
   buildToolsVersion "21.1.2"

   defaultConfig {
        minSdkVersion 18
        targetSdkVersion 21


        // Enabling multidex support.
        multiDexEnabled true
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }
   }

回答by sigrlami

1) You should sync with remote repos, with something like

1)您应该与远程存储库同步,例如

mvn install - U

mvn install - U

or in Android Studioor IntelliJ Ideago to Settingsfind Mavengroup, find subgroup Repositoriesand click Updateon fabrics repo.

或在Android StudioIntelliJ IdeaSettings查找Maven组,找到子组Repositories并单击Update面料回购。

enter image description here

在此处输入图片说明

2) If it doesn't help you should switch to jcenter()instead mavenCentral(), because fabric.io developers pushing updates to jcentral()and mavenCentral()might be outdated. More about difference between two: Android buildscript repositories: jcenter VS mavencentral

2)如果它不能帮助你应该改用jcenter()替代mavenCentral(),因为fabric.io开发商推更新jcentral()mavenCentral()可能已过时。更多关于两者之间的区别:Android buildscript repositories:jcenter VS mavencentral

回答by Jaya

This can occur when you are behind a proxy

当您在代理后面时可能会发生这种情况

回答by Arash Afsharpour

if you still have trouble with building the gradle after looking all the topics in Stack like i did for the past two days, there might be something else you should check if you used to use "Proxy" before, there's two file called gradle.properties in your gradle package.

如果像我过去两天那样查看 Stack 中的所有主题后仍然无法构建 gradle,那么您可能应该检查其他一些东西,如果您以前使用过“代理”,有两个文件名为 gradle.properties在你的 gradle 包中。

if you've used a proxy before there's a possibility that android studio added that information in one of those gradle.properties file, so take a look at them both and if you see anything like:

如果您之前使用过代理,那么 android studio 有可能在其中一个 gradle.properties 文件中添加了该信息,那么请查看它们,如果您看到以下内容:

systemProp.https.proxyHost=your_proxy_host
systemProp.https.proxyPort=your_proxy_port
systemProp.https.proxyUser=your_proxy_username
systemProp.https.proxyPassword=your_proxy_password

or

或者

systemProp.http.proxyHost=your_proxy_host
systemProp.http.proxyPort=your_proxy_port
systemProp.http.proxyUser=your_proxy_username
systemProp.http.proxyPassword=your_proxy_password

just remove them, the then invalidate cache and restart your android studio and run the project I'm sure you will be fine.

只需删除它们,然后使缓存无效并重新启动您的android studio并运行该项目我相信你会没事的。

回答by Rakshith Shetty

Turn on

打开

Offline work

离线工作

in settings -> Build,Execution... -> Gradle

在设置 -> Build,Execution... -> Gradle

回答by Ishan Sharma

For anyone still facing this problem, here's what you need to do:

对于仍然面临此问题的任何人,您需要执行以下操作:

  1. Read the answer by Arash Afsharpour
  2. Follow what he says
  1. 阅读Arash Afsharpour回答
  2. 按照他说的去做

If the problem still persists:

如果问题仍然存在:

There's a global .gradle/gradle.properties file somewhere in your system (In my case, it was in my Users home directory). This file has your proxy settings stored. Comment these lines.

在你的系统中的某个地方有一个全局的 .gradle/gradle.properties 文件(在我的例子中,它在我的用户主目录中)。该文件存储了您的代理设置。注释这些行。

This should get your project up and running.

这应该可以启动并运行您的项目。

Cheers!

干杯!