我在尝试从干净的构建(用于 Jenkins CI)中对我们的 Android 项目进行命令行构建时遇到问题。如果我在 Android Studio 中打开项目并运行Tools > Android > Sync Project with Gradle Files
,我随后可以从命令行构建。但是,如果我尝试从命令行运行./gradlew build
而不先在 Android Studio 中打开项目,则会收到以下构建失败:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':Redacted'.
> Could not resolve all dependencies for configuration ':Redacted:_debugCompile'.
> Could not find com.android.support:multidex:1.0.0.
Searched in the following locations:
https://repo1.maven.org/maven2/com/android/support/multidex/1.0.0/multidex-1.0.0.pom
https://repo1.maven.org/maven2/com/android/support/multidex/1.0.0/multidex-1.0.0.jar
https://jcenter.bintray.com/com/android/support/multidex/1.0.0/multidex-1.0.0.pom
https://jcenter.bintray.com/com/android/support/multidex/1.0.0/multidex-1.0.0.jar
http://download.crashlytics.com/maven/com/android/support/multidex/1.0.0/multidex-1.0.0.pom
http://download.crashlytics.com/maven/com/android/support/multidex/1.0.0/multidex-1.0.0.jar
Required by:
RedactedAndroid:Redacted:unspecified
> Could not find any version that matches com.android.support:support-v4:21.0.+.
Searched in the following locations:
https://repo1.maven.org/maven2/com/android/support/support-v4/maven-metadata.xml
https://repo1.maven.org/maven2/com/android/support/support-v4/
https://jcenter.bintray.com/com/android/support/support-v4/maven-metadata.xml
https://jcenter.bintray.com/com/android/support/support-v4/
http://download.crashlytics.com/maven/com/android/support/support-v4/maven-metadata.xml
http://download.crashlytics.com/maven/com/android/support/support-v4/
Required by:
RedactedAndroid:Redacted:unspecified
> Could not find any version that matches com.android.support:appcompat-v7:21.0.+.
Searched in the following locations:
https://repo1.maven.org/maven2/com/android/support/appcompat-v7/maven-metadata.xml
https://repo1.maven.org/maven2/com/android/support/appcompat-v7/
https://jcenter.bintray.com/com/android/support/appcompat-v7/maven-metadata.xml
https://jcenter.bintray.com/com/android/support/appcompat-v7/
http://download.crashlytics.com/maven/com/android/support/appcompat-v7/maven-metadata.xml
http://download.crashlytics.com/maven/com/android/support/appcompat-v7/
Required by:
RedactedAndroid:Redacted:unspecified
> Could not find any version that matches com.google.android.gms:play-services:6.5+.
Searched in the following locations:
https://repo1.maven.org/maven2/com/google/android/gms/play-services/maven-metadata.xml
https://repo1.maven.org/maven2/com/google/android/gms/play-services/
https://jcenter.bintray.com/com/google/android/gms/play-services/maven-metadata.xml
https://jcenter.bintray.com/com/google/android/gms/play-services/
http://download.crashlytics.com/maven/com/google/android/gms/play-services/maven-metadata.xml
http://download.crashlytics.com/maven/com/google/android/gms/play-services/
Required by:
RedactedAndroid:Redacted:unspecified
> Could not find any version that matches com.android.support:support-v4:[21,22).
Required by:
RedactedAndroid:Redacted:unspecified > com.facebook.android:facebook-android-sdk:3.22.0
> Could not find any version that matches com.android.support:appcompat-v7:21.+.
Required by:
RedactedAndroid:Redacted:unspecified > com.uservoice:uservoice-android-sdk:1.2.2
> Could not find com.android.support:support-v4:21..
Searched in the following locations:
https://repo1.maven.org/maven2/com/android/support/support-v4/21./support-v4-21..pom
https://repo1.maven.org/maven2/com/android/support/support-v4/21./support-v4-21..jar
https://jcenter.bintray.com/com/android/support/support-v4/21./support-v4-21..pom
https://jcenter.bintray.com/com/android/support/support-v4/21./support-v4-21..jar
http://download.crashlytics.com/maven/com/android/support/support-v4/21./support-v4-21..pom
http://download.crashlytics.com/maven/com/android/support/support-v4/21./support-v4-21..jar
Required by:
RedactedAndroid:Redacted:unspecified > com.uservoice:uservoice-android-sdk:1.2.2
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
据我所知,我的 Gradle 脚本中指定了所有正确的依赖项:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
还有我的应用级 Gradle 脚本:
...
dependencies {
...
compile 'com.android.support:multidex:1.0.0'
...
}
android {
...
另外,.gitignore 的一些内容:
# Android Studio and Gradle
build/
local.properties
.gradle
gradle-app.setting
*.iml
.idea/
*.ipr
*.iws
out/
.idea_modules/
为什么无法从干净的命令行构建中找到 multidex,我该如何解决这个问题?