简体   繁体   English

Android Studio:由于 gradle 分发 url 错误而无法构建应用程序

[英]Android Studio: Unable to build app due to gradle distribution url error

I know this question has been asked before but I haven't been able to fix the issue.我知道之前有人问过这个问题,但我一直无法解决这个问题。 I am running Android Studio version 3.1.4.我正在运行 Android Studio 3.1.4 版。 I am trying to run an app that I cloned from a Github repository.我正在尝试运行从 Github 存储库克隆的应用程序。 But even before I try to run it, I get this error:但即使在我尝试运行它之前,我也会收到此错误:

my-app: sync failed我的应用程序:同步失败

Cause: https://downloads.gradle.org/distributions-snapshots/gradle-4.4-20171031235950+0000-all.zip原因: https : //downloads.gradle.org/distributions-snapshots/gradle-4.4-20171031235950+0000-all.zip

How do I fix this error?我该如何解决这个错误? Thanks in advance.提前致谢。

You can check and change the distribution url in the properties file $rootDir/gradle/wrapper/gradle-wrapper.properties .您可以在属性文件$rootDir/gradle/wrapper/gradle-wrapper.properties检查和更改分发 url。 See property distributionUrl .请参阅属性distributionUrl

Value should be something as follows (update the gradle version depending on your Android Studio version)值应如下所示(根据您的 Android Studio 版本更新 gradle 版本)

distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

You can fix it by the following steps: (currently using Android 3.6.3)您可以通过以下步骤进行修复:(目前使用的是Android 3.6.3)

This worked for me.这对我有用。

  • Exit android studio then make the below changes.退出 android studio 然后进行以下更改。
  • Go to C:\\Users\\UserName.android and rename the build-cache folder to build-cache.bak .转到C:\\Users\\UserName.android并将build-cache文件夹重命名为build-cache.bak
  • Go to C:\\Users\\UserName.AndroidStudio3.6\\system and rename these folders:转到C:\\Users\\UserName.AndroidStudio3.6\\system并重命名这些文件夹:
    • caches to caches.bak cachescaches.bak
    • compiler to compiler.bak compilercompiler.bak
    • compile-server to compile-server.bak compile-servercompile-server.bak compile-server compile-server.bak
    • conversion to conversion.bak conversionconversion.bak
    • external_build_system to external_build_system.bak external_build_systemexternal_build_system.bak
    • frameworks to frameworks.bak frameworksframeworks.bak
    • gradle to gradle.bak gradlegradle.bak
    • resource_folder_cache to resource_folder_cache.bak resource_folder_cacheresource_folder_cache.bak
  • Open the Android Studio and open your project again.打开 Android Studio 并再次打开您的项目。

If the folder is not in the Android3.6 folder, move to the next step.如果该文件夹不在 Android3.6 文件夹中,请转到下一步。

I've encountered a similar error when I tried importing the Sunshine project from the Udacity Android development course.我在尝试从 Udacity Android 开发课程导入 Sunshine 项目时遇到了类似的错误。 I fixed the issue by downloading the mentioned zip file and extracted it to the C:\\Users\\<username>\\.gradle\\native folder.我通过下载提到的 zip 文件并将其解压缩到C:\\Users\\<username>\\.gradle\\native文件夹解决了该问题。

目录

Then in Gradle settings, use local Gradle distribution and set the Gradle home path to the downloaded gradle folder.然后在 Gradle 设置中,使用local Gradle distribution并将Gradle home路径设置为下载的 gradle 文件夹。

摇篮设置

Check this video for more information查看此视频了解更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM