问题描述
我正在做的项目是很久以前开发的,并且运行成功。现在,我想再次访问它并运行它以查看一些结果。
当我尝试构建项目时,我收到以下错误和 Connection_Reset”消息。
更新的 gradle:app:
plugins{
id 'com.android.application'
}
android {
compileSdkVersion 30
defaultConfig {
applicationId "example.com.thninxnet_00"
minSdkVersion 14
targetSdkVersion 30
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
buildToolsVersion "30.0.2"
}
dependencies {
implementation fileTree(include: ['*.jar'],dir: 'libs')
testImplementation 'junit:junit:4.12'
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:23.4.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation files('libs/universal-image-loader-1.9.5.jar')
}
更新 gradle:project:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
更新错误:
connection reset
解决方法
您使用的是 compileSdkVersion
和 targetSdkVersion
的 30
,但您的 buuldToolsVersion
是 25
,所以只是为了兼容性替换:
buildToolsVersion "25.0.1"
与:
buildToolsVersion "30.0.2"
并替换:
apply plugin: 'com.android.application'
与:
plugins{
id 'com.android.application'
}
并告知我们结果。
编辑:
还有Invalidate Caches
:
File -> Invalidate Caches -> Invalidate and Restart
编辑 2:
当 gradle
无法连接到 servers
以检索所需的 libraries
时,可能会发生连接重置,因此您可以做的是:
- 检查您的
internet
连接是否稳定,可能是由于互联网连接不稳定。 - 如果您的互联网连接稳定,那么问题可能是与
gradle servers
的连接可能被阻止,因此请使用 VPN(会更改您的 IP)并再次尝试重建您的项目。 - 另一个问题可能是您的
Antivirus
软件或Firewall
可能阻止了Android Studio
,因此请务必禁用防火墙和防病毒软件并重建您的项目。
无法说明后面的错误,但构建期间的连接重置错误有时是由于互联网连接不稳定。也许这种不稳定的互联网连接是同步失败和后续错误的原因。
,google()
已添加到 Gradle v4 中,因此请确保您使用正确的 Gradle 插件版本
请尝试使用
更新您的项目级 Gradle 文件classpath 'com.android.tools.build:gradle:3.5.3'
并在您的 gradle-wrapper.properties
中添加此行
distributionUrl=\
https\://services.gradle.org/distributions/gradle-4.1-x-all.zip
或者,在旧版本的 Android Studio 中,您可以使用 google()
构造对 maven
使用等效项,但尝试将其放在 jcenter()
之后
maven {
url 'https://maven.google.com'
}