I tried to assembleDebug
using CircleCI, but it must fail to build(preDex).
Why can't I do that?
Problem
./gradlew assembleProductionDebug died unexpectedly Building 92%3% > :app:preDexProductionDebugaction ./gradlew assembleProductionDebug failed
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
I had the same issue. It turned out that I had to disable preDex for the ci builds.
Put this in the 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
}
}
}
Then you can build on your ci with the following command:
./gradlew ... -PdisablePreDex
So I had the same issue and found even though java and gradle heap sizes were being set they were not being fully respected as the dex tasks spawn a ton of fresh threads with their own heap size (check your memory log and you may see the same) If so, the method I used to fix it for Android Gradle plugin 1.3 and above was to use:
-Pcom.android.build.threadPoolSize=1
This will stop the dexing step spawning a bunch of fresh 1G threads. There is also:
-Porg.gradle.parallel=false
But I found this to be ineffective when using multidex for some reason. For CircleCI I found this to be the most consistent build task, if a little slow. I'm sure the heap sizes can be tweaked a little further for better results:
./gradlew build -PpreDexEnable=false -Pcom.android.build.threadPoolSize=1 -Dorg.gradle.parallel=false -Dorg.gradle.jvmargs="-Xms512m -Xmx512m" -Dorg.gradle.daemon=false
I had a same problem, it was caused since the memory limits per a container (it is 4GB). For me, the solution was to use: gradle.properties
org.gradle.jvmargs=-Xms256m -Xmx2048m
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With