6

我尝试assembleDebug使用 CircleCI,但它必须无法构建(preDex)。为什么我不能这样做?

  • 使用 ProductFlavor(名称为生产)
  • Android Gradle ver.1.1.0-rc1

问题

./gradlew assembleProductionDebug 意外死亡 Building 92%3% > :app:preDexProductionDebugaction ./gradlew assembleProductionDebug 失败

圆圈.yml

general:
  artifacts:
    - "app/build/outputs/apk/app-production-release-unaligned.apk"
machine:
  java:
    version: openjdk7
  environment:
    ANDROID_HOME: /usr/local/android-sdk-linux

dependencies:
  pre:
    - echo y | android update sdk --no-ui --all --filter "build-tools-21.1.2"
    - echo y | android update sdk --no-ui --all --filter "platform-tools"
    - echo y | android update sdk --no-ui --all --filter "tools"
    - echo y | android update sdk --no-ui --all --filter "extra-google-google_play_services"
    - echo y | android update sdk --no-ui --all --filter "extra-google-m2repository"
    - echo y | android update sdk --no-ui --all --filter "extra-android-m2repository"
    - echo y | android update sdk --no-ui --all --filter "extra-android-support"
    - echo y | android update sdk --no-ui --all --filter "android-21"
    - git submodule sync
    - git submodule update --init
  cache_directories:
    - ~/.android
    - ~/android
  override:
    - ./gradlew dependencies

test:
  override:
    - ./gradlew test

deployment:
  master:
    branch: master
    commands:
      - ./gradlew assembleProductionDebug
4

3 回答 3

11

我遇到过同样的问题。事实证明,我不得不为 ci 构建禁用 preDex。

把它放在根目录 build.gradle下:

project.ext.preDexLibs = !project.hasProperty('disablePreDex')

subprojects {
    project.plugins.whenPluginAdded { plugin ->
        if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) {
            project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
        } else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
            project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
        }
    }
}

然后您可以使用以下命令在您的 ci 上构建:

./gradlew ... -PdisablePreDex
于 2015-08-07T12:24:37.673 回答
6

所以我遇到了同样的问题,发现即使设置了 java 和 gradle 堆大小,它们也没有得到充分尊重,因为 dex 任务产生了大量具有自己堆大小的新线程(检查你的内存日志,你可能会看到相同的) 如果是这样,我为 Android Gradle 插件 1.3 及更高版本修复它的方法是使用:

-Pcom.android.build.threadPoolSize=1 

这将停止生成一堆新的 1G 线程的 dexing 步骤。还有:

-Porg.gradle.parallel=false

但是由于某种原因,我发现在使用 multidex 时这无效。对于 CircleCI,我发现这是最一致的构建任务,虽然有点慢。我确信可以进一步调整堆大小以获得更好的结果:

./gradlew build -PpreDexEnable=false -Pcom.android.build.threadPoolSize=1 -Dorg.gradle.parallel=false -Dorg.gradle.jvmargs="-Xms512m -Xmx512m" -Dorg.gradle.daemon=false
于 2015-10-30T09:18:02.630 回答
2

我遇到了同样的问题,这是因为每个容器的内存限制(它是 4GB)引起的。对我来说,解决方案是使用: gradle.properties

org.gradle.jvmargs=-Xms256m -Xmx2048m
于 2015-07-15T11:33:09.883 回答