安卓:在升级到Android Studio 2.3后无法构建项目

3

因此,我很高兴将我的Android Studio从稳定版2.2更新到金丝雀通道2.3。

但是,不幸的是,它有一个严重的错误。项目无法构建。 我尝试打开以前的项目并尝试创建新的示例应用程序,但仍然遇到以下相同的错误:

Gradle 'MyApplication' project refresh failed
Error:A problem occurred configuring project ':app'.

build.gradle(project):

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0-alpha1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle(app):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.example.chint.myapplication"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.0.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
    compile 'com.android.support:design:25.0.0'
    testCompile 'junit:junit:4.12'
}

我是不是唯一遇到这个问题的人?

1
适当降低评分并给出理由总是有帮助的。 - Chintan Soni
4个回答

2

请注意,当出现此对话框时要小心:

enter image description here

选择“稍后提醒”,而不是“更新”

保留您已有的版本。

如果您已经按下了“更新”按钮,请在build.gradle(project)文件中将您的Android Gradle插件类路径回滚到以下版本:

classpath 'com.android.tools.build:gradle:2.2.2' 

这对我很有帮助。

1

你需要手动更新Android Studio gradle。

第一步:

按照以下路径获取你的gradle版本

C:\Users\[USER_NAME]\.gradle\wrapper\dists

这里你会得到“gradle-X.X”(X代表版本),在我的情况下是“gradle-3.3-all”。

第二步:

前往以下链接:

https://services.gradle.org/distributions/

下载对应版本的zip文件,然后将其粘贴到具有长随机名称的最后一个文件夹中。 C:\Users\[USER_NAME]\.gradle\wrapper\dists\gradle-x.x\55gk2rcmfc6p2dg9u9ohc31212 这里 现在打开Android Studio,希望这样能够起作用。

进行一些格式调整,使其更易读。 - Gahan
Yup Gahan,谢谢Dwhitz。 - codercode

0

我遇到了类似的问题,并通过添加2个字符来解决它...

并且在将gradle-wrapper.properties更新为目标3.2.1之后,一切都很完美。

distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-all.zip

0
If you import external libraries apply  changes for "allprojects"

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接