构建Android项目时出错

时间:2017-07-17 04:29:36

标签: android android-studio gradle android-gradle

当我尝试构建我的android项目时,它会显示一些gradle错误。错误如下,

Error:Could not find com.android.tools.build:gradle:2.2.3.
Searched in the following locations:
    https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.pom
    https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.jar
Required by:
    D4D.libs:ViewPagerIndicator-Library:unspecified

如果有人知道如何解决此错误,请帮助我。

我的 build.gradle

// 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.2.3'

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

2 个答案:

答案 0 :(得分:0)

这是因为构建过程无法在Maven存储库中找到依赖项。在项目级 build.gradle 文件中添加 jcenter()以及 mavenCentral()

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

see this

答案 1 :(得分:0)

根据这个答案https://stackoverflow.com/a/39654136/8284461,您可能需要在您的存储库中添加mavenCentral()。 gradle会是这样的

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }

    dependencies {

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

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