当我尝试使用 gradle 包装器构建项目时,出现以下错误:
./gradlew
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all files for configuration ':app:classpath'.
> Could not find com.android.tools.build:gradle:3.0.1.
Searched in the following locations:
https://maven.fabric.io/public/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
https://maven.fabric.io/public/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.jar
https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.jar
Required by:
project :app
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
相同的项目在 Android Studio 中构建正常。
我已经查过了this https://stackoverflow.com/questions/45188703/could-not-find-com-android-tools-build-gradle3-0-0-alpha7/4518891 and this https://stackoverflow.com/questions/47012681/could-not-find-com-android-tools-buildgradle3-0-0但我使用的是 gradle 包装器版本 4.1,添加了 google() 存储库,甚至尝试设置android.enableAapt2=false
。还有其他提示吗?谢谢。
My root build.gradle
file:
// 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.0.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
}
My gradle-wrapper.properties
file:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
更新:加布里埃尔是对的。我也想将存储库添加到app/build.gradle file
:
...
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
...
我想我对这个声明感到困惑“要将这些库之一添加到您的构建中,请将 Google 的 Maven 存储库包含在您的顶级 build.gradle 文件中” in here https://developer.android.com/studio/build/dependencies.html.