Trouble building Android project


#1

I am new to CircleCI and I’m not sure how to setup my circle.yml to get my Android projects to build. I have a top level repo in github which contains two subdirectories each containing a different app. I am trying to configure the circle.yml such that both projects should get built and generate the APKs for each app. From what I understand so far, the circle.yml should live in the root folder and contain a build_dir configuration pointing to the app. But as mentioned above, I have two apps at the top level and build_dir doesn’t expect an array. Any insights on how I might be able to accomplish this?


#2

If it’s a single command or two to build the second app, you can do it by using the pwd modifier.

So your circle.yml file would be as such:

- command to build first app
- command to build second app:
    pwd: 
      path for second build dir

ref: https://circleci.com/docs/configuration#modifiers


#3

Thanks for the tip, will try that. I tried building a single app, but that is also failing with the error below. Any idea what might be the cause of this failure?

“> Building 92% > :app:transformClassesWithDexForDebug./gradlew clean assembleDebug died unexpectedly”

Here’s my circle.yml:

general:
build_dir: NextHelper

test:
override:
- ./gradlew clean assembleDebug
- cp -r app/build/outputs $CIRCLE_ARTIFACTS


#4

Perhaps https://stackoverflow.com/questions/33369163/execution-failed-for-task-apptransformclasseswithdexfordebug-while-implement will help?

I’ve not built on android so without seeing the code or a more detailed error I probably won’t be much help.


#5

I’m able to build the code just fine on my local machine using the same command and also on Android studio. So not sure if it’s something in the code or config issue. Happy to share more details if I can get help with this. What information would you need?


#6

Since it’s failing a Gradle task, do you mind sharing your Gradle file?

Or just the assembleDebug task if you prefer.


#7

Just noticed this error at the top of the page:
“Your build has exceeded the memory limit of 4G on 1 container. The results of this build are likely invalid. We have taken a snapshot of the memory usage at the time, which you can find in a build artifact named memory-usage.txt. The RSS column in this file shows the amount of memory used by each process, measured in kilobytes.”

Is this something that can happen in a small’ish project with 10-15 gradle dependencies?


#8

Ah, that would explain why the task died then.

Android likes to go crazy with memory, give https://circleci.com/docs/oom/#out-of-memory-errors-in-android-builds a look :smile:


#9

So I added the memory configuration as well as second app to circle.yml. Now the first build (NextHelper) works, but the second (NextManager) build still fails with the same memory error. Here is my circle.yml with both builds. Any tips on how to make the second build work too?

machine:
environment:
GRADLE_OPTS: ‘-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"’

dependencies:
override:
- (./gradlew dependencies):
pwd:
./NextHelper
- (./gradlew dependencies):
pwd:
./NextManager

test:
override:
- (./gradlew clean assembleDebug):
pwd:
./NextHelper
- (./gradlew clean assembleDebug):
pwd:
./NextManager


#10