【问题标题】:Building project failes and causes connection reset构建项目失败并导致连接重置
【发布时间】:2021-01-14 17:08:43
【问题描述】:

我正在做的项目是很久以前开发的,并且运行成功。现在,我想再次访问它并运行它以查看一些结果。

当我尝试构建项目时,我收到以下错误和 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

【问题讨论】:

  • 您可能还需要在allprojects.repositories 下添加google()
  • 我想你已经从github 拉了它。 Git 不会保存您的受保护文件。这意味着当您将项目推送到 github 时,一些源代码会自动删除。根据您给出的那张图片,问题出在您的依赖项中(在实施上有问题)。照@maurice 说的做。我认为某些库丢失并尝试再次同步。
  • @maurice 实际上现在我收到了上面提到的那个错误。你明白了吗?
  • @LetsamrIt 您在版本控制中遇到问题。原因,那个项目是旧版本的,现在你正在使用jar的更新版本和一些互联网库。我不知道如何解决这个问题。所以,对不起!
  • 你把 google() 放在 jcenter() 上面 buildscriptallprojects

标签: android gradle android-gradle-plugin build.gradle


【解决方案1】:

您使用的是compileSdkVersiontargetSdkVersion30,但您的buuldToolsVersion25,所以只是为了兼容性替换:

buildToolsVersion "25.0.1"

与:

buildToolsVersion "30.0.2"

还有替换:

apply plugin: 'com.android.application'

与:

plugins{
   id 'com.android.application'
}

并向我们提供结果。

编辑: 还有Invalidate Caches也:

文件 -> 使缓存无效 -> 无效并重新启动

编辑 2:

gradle 无法连接到servers 以检索所需的libraries 时,可能会发生连接重置,因此您可以做的是:

  1. 检查您的internet 连接是否稳定,可能是由于互联网连接不稳定。
  2. 如果您有稳定的互联网连接,则问题可能是与 gradle servers 的连接可能被阻止,因此请使用 VPN(这会更改您的 IP)并再次尝试重建您的项目。
  3. 另一个问题可能是您的 Antivirus 软件或 Firewall 可能会阻止 Android Studio,因此请务必禁用防火墙和防病毒软件并重建您的项目。

【讨论】:

  • 我更新了问题。我按照您提出的步骤进行操作,但我在更新的问题中收到了错误帖子。请阅读
  • @LetsamrIt 我编辑了我的答案,看看吧。
【解决方案2】:

不能说后面的错误,但构建过程中的连接重置错误有时是由于互联网连接不稳定。也许这种不稳定的互联网连接是同步失败和后来出现错误的原因。

【讨论】:

    【解决方案3】:

    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 中,您都可以使用 maven 构造来使用 google() 的等效项,但请尝试将其放在 jcenter() 之后

    maven {
        url 'https://maven.google.com'
    }
    

    【讨论】:

      猜你喜欢
      • 2014-02-03
      • 2019-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-09
      相关资源
      最近更新 更多