Android Studio 3.1.3 Gradle 同步错误。无法下载 Gradle-Core.jar
Posted
技术标签:
【中文标题】Android Studio 3.1.3 Gradle 同步错误。无法下载 Gradle-Core.jar【英文标题】:Android Studio 3.1.3 Gradle Sync Error. Could Not Download Gradle-Core.jar 【发布时间】:2018-12-06 21:53:55 【问题描述】:我是一名计算机科学专业的学生,我正在尝试熟悉构建应用程序以作为暑期爱好。但是,在过去的几天里,当我尝试同步 Gradle 时,它给了我同样的错误,说明
gradle-core.jar 无法下载。
我将在这篇文章的底部发布完整的错误消息。
当然,我确定我不是在离线模式下工作。最重要的是,我强制使用http://
获取https://
源。我还在gradle-wrapper.properties
文件中将distributionUrl 的https://
更改为http://。我尝试了不同的代理,并将build.gradle
文件中的存储库更改为jcenter(), mavenCentral(), and google().
我什至尝试与我的防火墙同步,并且关闭了防病毒软件,但没有任何效果。您将在下面找到我的完整错误消息。
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'androidStudioProjects'.
...
at org.gradle.configuration.project.LifecycleProjectEvaluator.doConfigure(LifecycleProjectEvaluator.java:64)
... 84 more
Caused by: org.gradle.internal.resolve.ArtifactResolveException: Could not download gradle-core.jar (com.android.tools.build:gradle-core:3.1.3)
at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver$RemoteRepositoryAccess.resolveArtifact(ExternalResourceResolver.java:506)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository$ResolveAndCacheRepositoryAccess.resolveArtifact(CachingModuleComponentRepository.java:409)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.BaseModuleComponentRepositoryAccess.resolveArtifact(BaseModuleComponentRepositoryAccess.java:65)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.memcache.InMemoryCachedModuleComponentRepository$CachedAccess.resolveArtifact(InMemoryCachedModuleComponentRepository.java:124)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ErrorHandlingModuleComponentRepository$ErrorHandlingModuleComponentRepositoryAccess.resolveArtifact(ErrorHandlingModuleComponentRepository.java:171)
...
... 6 more
Caused by: org.gradle.api.resources.ResourceException: Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle-core/3.1.3/gradle-core-3.1.3.jar'.
at org.gradle.internal.resource.ResourceExceptions.failure(ResourceExceptions.java:74)
at org.gradle.internal.resource.ResourceExceptions.getFailed(ResourceExceptions.java:57)
at org.gradle.internal.resource.transfer.AccessorBackedExternalResource.withContentIfPresent(AccessorBackedExternalResource.java:146)
...
at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver$RemoteRepositoryAccess.resolveArtifact(ExternalResourceResolver.java:499)
... 27 more
Caused by: javax.net.ssl.SSLException: SSL peer shut down incorrectly
at sun.security.ssl.InputRecord.readV3Record(InputRecord.java:596)
at sun.security.ssl.InputRecord.read(InputRecord.java:532)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:940)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:105)
at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:139)
at org.apache.http.impl.io.SessionInputBufferImpl.read(SessionInputBufferImpl.java:200)
...
at org.gradle.internal.resource.transfer.AccessorBackedExternalResource.withContentIfPresent(AccessorBackedExternalResource.java:137)
... 44 more
(编辑):以下是我的相关文件
build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript
ext.kotlin_version = '1.2.30'
repositories
jcenter()
mavenCentral()
google()
dependencies
classpath 'com.android.tools.build:gradle:3.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
allprojects
repositories
jcenter()
mavenCentral()
google()
task clean(type: Delete)
delete rootProject.buildDir
gradle-wrapper.properties:
#Tue Jun 26 21:50:19 MDT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-4.4-all.zip
gradle.properties:
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
settings.gradle:
include ':app'
local.properties:
## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file should *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=C\:\\Users\\jddah\\AppData\\Local\\Android\\Sdk
【问题讨论】:
请编辑您的帖子以包含任何相关文件(build.gradle、gradle.properties 等) @jddahl19 有什么解决办法吗? @ArnoldBrown 我修复了它,但我不太确定如何。我卸载了 Android Studio 并删除了我之前的所有设置。然后我重新安装了 haxm,发现 VT-x 在我的 Bios 中被禁用,所以我启用了它并重新安装了 Android Studio 并允许它与新的 gradle 设置同步。在所有这些步骤之后,Gradle 开始为我同步,所以我不确定这些事情中的任何一个是否单独解决了我的问题,或者它是否是解决问题的所有东西的集合。试试看吧 @jddahl19 感谢您的回复。我也这样做了,因为我觉得重新安装比发现问题并由于工作紧迫而修复要容易得多。 【参考方案1】:尝试将 google()
作为 first 回购,如下所示。对于您现有的 Android Studio 项目,不要将其放在 jcenter()
和 mavenCentral()
下。
repositories
google() // make this repo as the first one if Android Gradle Plugin is upgraded from 2.x to 3.x.
jcenter()
mavenCentral()
对于那些使用 Android Gradle 插件较低版本的 React Native 或 CordovaLib 项目,例如2.2.3,您可以尝试将google()
替换为以下,但请记住将其作为第一个repo选择。
repositories
// google()
maven
url "https://maven.google.com"
jcenter()
清理所有旧的.gradle
缓存,然后执行新的同步。
【讨论】:
我的答案是把 google() repo 作为 first repo 源,它曾经解决了我同样的问题。【参考方案2】:就我而言,对于 gradle:2.2.3
allprojects
repositories
maven url 'https://maven.google.com' // now here
mavenLocal()
jcenter()
maven url "$rootDir/../node_modules/react-native/android"
maven url 'https://maven.google.com' // was here
希望有帮助:)
【讨论】:
【参考方案3】:将项目级别的gradle插件版本更新到最新版本并重新构建项目..
classpath 'com.android.tools.build:gradle:3.2.1'
检查您是否输入正确。如果仍然无法正常工作,请检查 Android Gradle 插件发行说明以找到正确的 gradle 插件版本。 https://developer.android.com/studio/releases/gradle-plugin
【讨论】:
【参考方案4】:它读取
原因:javax.net.ssl.SSLException: SSL peer 错误关闭
这意味着 SSL 证书或信任库存在问题。
正在下载的 JAR URL 是正确的,可以获取它。
issue 也列在 Gradle GitHub 上...
...在gradle.propteries
中首选 IPv4 可能会有所帮助:
org.gradle.jvmargs=-Djava.net.preferIPv4Stack=true
以及启用 SSL 和握手日志记录:
org.gradle.jvmargs=-javax.net.debug=ssl,handshake
另见Debugging SSL/TLS Connections。
【讨论】:
以上是关于Android Studio 3.1.3 Gradle 同步错误。无法下载 Gradle-Core.jar的主要内容,如果未能解决你的问题,请参考以下文章