Java Android Studio 3.1.3 Gradle 同步错误。无法下载 Gradle-Core.jar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51072319/
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
Android Studio 3.1.3 Gradle Sync Error. Could Not Download Gradle-Core.jar
提问by macaato
I am a computer science student and I am attempting to get familiar with building applications for a summertime hobby. However, for the past few days when I try to sync Gradle it gives me the same error stating that
我是一名计算机科学专业的学生,我正在尝试熟悉为夏季爱好构建应用程序。但是,在过去的几天里,当我尝试同步 Gradle 时,它给了我同样的错误,指出
gradle-core.jar could not be downloaded.
gradle-core.jar 无法下载。
I will post the full error message at the bottom of this post.
我会在这篇文章的底部发布完整的错误信息。
Of course, I made sure that I am NOT working in offline mode. On top of that I am forcing https://
sources to be fetched using http://
. I have also changed the https://
for the distributionUrl to http:// in the gradle-wrapper.properties
file. I have tried different proxies and have changed the repositories in the build.gradle
file to have jcenter(), mavenCentral(), and google().
当然,我确保我没有在离线模式下工作。最重要的是,我强制https://
使用http://
. 我还将文件中https://
的 distributionUrl更改为 http:// gradle-wrapper.properties
。我尝试了不同的代理,并将build.gradle
文件中的存储库更改为jcenter(), mavenCentral(), and google().
I have even attempted to sync with my firewall and antivirus turned off and nothing is working. Below you will find my entire error message.
我什至试图与我的防火墙和防病毒软件同步,但没有任何效果。您将在下面找到我的整个错误消息。
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
(EDIT): Below are my relevant files
(编辑):以下是我的相关文件
build.gradle:
构建.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:
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:
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:
设置.gradle:
include ':app'
local.properties:
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
回答by shizhen
Try to put google()
as the firstrepo as below. Don'tput it under jcenter()
and mavenCentral()
for your existing Android Studio projects.
尝试将其google()
作为第一个repo,如下所示。不要把它放在jcenter()
和mavenCentral()
您现有的Android Studio项目。
repositories {
google() // make this repo as the first one if Android Gradle Plugin is upgraded from 2.x to 3.x.
jcenter()
mavenCentral()
}
For those React Nativeor CordovaLibprojects that are with Android Gradle Plugin lower versions, e.g. 2.2.3, you can try to replace the google()
with below, but remember to put it as the first repo selection.
对于Android Gradle Plugin低版本的React Native或者CordovaLib项目,比如2.2.3,你可以尝试google()
用下面的替换,但记得把它作为第一个repo选择。
repositories {
// google()
maven {
url "https://maven.google.com"
}
jcenter()
}
Clean up all your old .gradle
caches and then perform a new Sync.
清理所有旧.gradle
缓存,然后执行新的同步。
回答by Martin Zeitler
it reads
它读
Caused by: javax.net.ssl.SSLException: SSL peer shut down incorrectly
引起:javax.net.ssl.SSLException:SSL 对等方关闭不正确
which means, that there is an issue with either the SSL certificate or the trust-store.
这意味着 SSL 证书或信任库存在问题。
the JAR URL being downloaded is otherwise correct, can fetch it.
正在下载的 JAR URL 否则正确,可以获取它。
the issueis also listed on the Gradle GitHub...
该问题也列在 Gradle GitHub 上...
... prefering IPv4 in gradle.propteries
might help:
... 更喜欢 IPv4gradle.propteries
可能会有所帮助:
org.gradle.jvmargs=-Djava.net.preferIPv4Stack=true
as well as, to enable logging for SSL & handshakes:
以及,启用 SSL 和握手的日志记录:
org.gradle.jvmargs=-javax.net.debug=ssl,handshake
also see Debugging SSL/TLS Connections.
另请参阅调试 SSL/TLS 连接。
回答by bGuom
Update the Project level gradle plugin version to the latest version and rebuild the project..
将项目级别的gradle插件版本更新为最新版本并重新构建项目..
classpath 'com.android.tools.build:gradle:3.2.1'
check whether you have typed it correctly. if not still working check the Android Gradle plugin release note to find correct gradle plugin versions. https://developer.android.com/studio/releases/gradle-plugin
检查您是否输入正确。如果仍然无法正常工作,请查看 Android Gradle 插件发行说明以找到正确的 gradle 插件版本。 https://developer.android.com/studio/releases/gradle-plugin
回答by tokinonagare
In my case, for gradle:2.2.3
就我而言,对于 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
}
}
hope helpful : )
希望有帮助:)