【问题标题】:How do I cause gradle command-line builds to install multidex from a clean build?如何使 gradle 命令行构建从干净的构建中安装 multidex?
【发布时间】:2015-03-12 23:34:58
【问题描述】:

我在尝试从干净的构建(用于 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,我该如何解决这个问题?

【问题讨论】:

    标签: android command-line gradle android-multidex


    【解决方案1】:

    Android Studio 和我的命令行构建使用不同的 Android SDK 安装。我在命令行上使用的那个没有安装一些必需的 Extras 包。一旦我安装了它们,构建就可以正常工作了。

    【讨论】:

      猜你喜欢
      • 2018-11-15
      • 1970-01-01
      • 1970-01-01
      • 2011-10-10
      • 1970-01-01
      • 2019-11-25
      • 2013-07-04
      • 2018-09-28
      • 1970-01-01
      相关资源
      最近更新 更多