【问题标题】:Gradle assembleDebug and preDexDebug fail with CircleCIGradle assembleDebug 和 preDexDebug 因 CircleCI 而失败
【发布时间】:2015-10-30 17:18:02
【问题描述】:

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

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

问题

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

circle.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

【问题讨论】:

  • 你好,我在 CircleCI 工作。您介意在 sayhi@circleci.com 上给我们留言,以便我们收集有关您的项目的更多信息并让事情为您工作吗?
  • 你解决了吗?我有同样的问题。

标签: android gradle circleci


【解决方案1】:

我有同样的问题。结果我不得不为 ci 构建禁用 preDex。

把它放在 root 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

【讨论】:

    【解决方案2】:

    所以我遇到了同样的问题,发现即使设置了 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
    

    【讨论】:

    • 太棒了!我在谷歌上搜索试图找出发生了什么。这就是答案...
    【解决方案3】:

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

    org.gradle.jvmargs=-Xms256m -Xmx2048m
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-10
      • 2021-06-30
      • 1970-01-01
      • 2022-12-16
      • 2020-10-25
      • 2019-12-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多