【问题标题】:Can't build/sync new or existing projects after Android Studio upgrade to 3.1Android Studio 升级到 3.1 后无法构建/同步新项目或现有项目
【发布时间】:2018-09-05 06:34:50
【问题描述】:

我刚刚从 Android Studio 3.0.1 升级到 3.1,现在我无法为我的任何项目构建或使用编辑器。 Gradle 正在尝试同步,但始终无法下载一些 .pom 文件,尽管我可以在浏览器中很好地下载它们,我没有使用代理并且我的防火墙没有出站限制。我已尝试卸载 Kotlin 插件清除缓存/重新启动,但我无法构建 AS。我什至无法让它构建/同步全新的、完全空的项目。有谁知道如何解决或解决此问题?

Android Studio 3.1
Build #AI-173.4670197, built on March 22, 2018
JRE: 1.8.0_152-release-1024-b02 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 7 6.1

这是一个新的空项目,大约在创建 10 分钟后:

这是一个在升级之前一直在构建的现有项目。现在,它只是花时间尝试从多个站点下载此文件,然后失败并出现与上图相同的错误:

编辑:build.gradle(项目)

// 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:3.1.0'


        // 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
}

编辑:build.gradle(模块)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.stredgic.servicenotificationdev"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

【问题讨论】:

    标签: android gradle build pom.xml


    【解决方案1】:

    最后我不得不硬着头皮重新安装 Android Studio 来解决这个问题。以下是我为遇到此问题的任何人(Windows 7)采取的具体步骤:

    • 备份的 Android Studio 设置 (File -> Export Settings...)
    • 已卸载 Android Studio。我选择删除所有内容,但这丢弃了我的开发密钥,所以一旦我恢复运行并重新安装我的所有应用程序,我必须重新安装。首先备份它们,除非您不介意从头开始
    • c:\Users\XXXX 文件夹(其中XXXX 是我的用户名)中,我删除了.gradle 和所有Android Studio 目录。我之前在尝试解决问题时实际上已经删除了.gradle,但是在 AS 重新创建它之后我又删除了它
    • 安装了较新的 Android Studio 3.1 exe,从 Google 新下载
    • 导入了我之前备份的设置 (File -> Import Settings...)
    • 重新安装我的所有应用,因为它们已由我安装较新版本的 Android Studio 时生成的新开发密钥签名

    我希望这对遇到同样问题的人有所帮助,因为这让我浪费了 14 多个小时的挫败感和时间。我建议,如果您将来升级 Android Studio 的最小功能,您应该:

    • 仅当它提供所需功能或解决您遇到的问题时才这样做
    • 在升级主计算机的同时保留一台能够继续开发的备用计算机...
    • ...或者,如果您没有...只在您可以腾出一两天浪费时间的时候这样做

    【讨论】:

      【解决方案2】:

      单击右下方面板中的Open File 链接。

      确保google()jcenter() 是这些文件中buildscript -> repositories 部分的前两行,将google() 放在jcenter() 之前。

      【讨论】:

      • 感谢您的回复@Cloudream,不幸的是,这些是该部分中仅有的两行,并且已经按该顺序排列
      猜你喜欢
      • 2017-07-24
      • 2018-08-21
      • 1970-01-01
      • 2020-07-27
      • 2018-09-05
      • 2021-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多