Webster
Webster

Reputation: 1153

Circle CI 2.0 Android assembleDebug always failed

Every time the Circle CI run ./gradlew assembleDebug part, it always fail. I don't know where's the problem but I've tried many ways like I ran it with and without daemon or setting up the gradle.properties. I've been searching for the answers on google and SO but still can't find the right one. Here is the error

Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)

Here's my config.yml

version: 2
references:
  ## Workspaces
  workspace: &workspace
    ~/src

  save_workspace_artifacts: &save_workspace_artifacts
    store_artifacts:
      path: outputs/outputs/apk

  attach_workspace_artifacts: &attach_workspace_artifacts
    attach_workspace:
      at: outputs

  ## Docker image configurations
  android_config: &android_config
    working_directory: *workspace
    docker:
      - image: circleci/android:api-28-alpha
    environment:
      TERM: dumb
      _JAVA_OPTIONS: "-Xmx2048m -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap"
      GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m"'

  ## Cache
  gradle_key: &gradle_key
    jars-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}

  gems_key: &gems_key
    gems-{{ checksum "Gemfile.lock" }}

  restore_gradle_cache: &restore_gradle_cache
    restore_cache:
      key: *gradle_key

  restore_gems_cache: &restore_gems_cache
    restore_cache:
      key: *gems_key

  save_gradle_cache: &save_gradle_cache
    save_cache:
      key: *gradle_key
      paths:
        - ~/.gradle
        - ~/.m2

  save_gems_cache: &save_gems_cache
    save_cache:
      key: *gems_key
      paths:
        - vendor/bundle

  ## Dependencies
  ruby_dependencies: &ruby_dependencies
    run:
      name: Download Ruby Dependencies
      command: bundle update || bundle install --path vendor/bundle

  android_dependencies: &android_dependencies
    run:
      name: Download Android Dependencies
      command: ./gradlew androidDependencies

  clean_gradle: &clean_gradle
    run:
      name: Clean gradle || ./gradlew clean
      command: ./gradlew clean

  build_apk: &build_apk
    run:
      name: Build apk || ./gradlew assembleDebug
      command: ./gradlew clean assembleDebug --no-daemon --stacktrace

  deploy_to_hockey: &deploy_to_hockey
    run:
      name: Deploy to hockey app
      command: sh ./scripts/deployHockeyApp.sh

jobs:
  ## Run unit tests
  test_unit:
    <<: *android_config
    steps:
      - checkout
      - run:
          name: Current branch
          command: echo ${CIRCLE_BRANCH}
      - *restore_gradle_cache
      - *restore_gems_cache
      - *ruby_dependencies
      - *android_dependencies
      - *save_gradle_cache
      - *save_gems_cache
      - run:
          name: Run unit tests
          command: bundle exec fastlane unit_tests
      - store_artifacts:
          path: app/build/reports/
          destination: /reports/
      - store_test_results:
          path: app/build/test-results/
          destination: /test-results/

  deploy:
    <<: *android_config
    steps:
      - checkout
      - run:
          name: Upload to HockeyApp
          command: sh ./scripts/deployHockeyApp.sh

  deploy_hockeyapp:
    docker:
      - image: circleci/android:api-28-alpha
    environment:
      JVM_OPTS: -Xmx4G
    steps:
      - checkout
      - restore_cache:
          key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
      - run:
          name: Download Dependencies
          command: ./gradlew androidDependencies
      - save_cache:
          paths:
          - ~/.gradle
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
      - *clean_gradle
      - *build_apk
      - store_artifacts:
          path: app/build/outputs/apk/development
          destination: apks/
      - *deploy_to_hockey

workflows:
  version: 2
  workflow:
    jobs:
      - test_unit
      - deploy_hockeyapp:
          filters:
            branches:
              only:
                - beta
                - develop
                - /test\/ci_fastfile
                - /test\/ci_fastfile2/
                - /test\/ci_fastfile2
      - deploy_play_store:
          filters:
            branches:
              only:
                - production
          requires:
            - test_unit

It always failed on step *build_apk

Really appreciate any comments / answer, has been working on it since 2 days ago.

Upvotes: 0

Views: 898

Answers (1)

dilix
dilix

Reputation: 3893

Difficult to say what fails without access to your CircleCI build machine (to check logs etc) but here's the config of CiclreCI v2 that build APK and deliver it to Fabric beta, also similar works to delivery APK to google play alpha/beta/prod channels.

I use this build as a template and it works on several projects for both Debug and Release builds with proguard or not.

version: 2
jobs:
  develop_build:
    working_directory: ~/code
    docker:
      - image: circleci/android:api-27-node8-alpha
    environment:
      JVM_OPTS: -Xmx3200m
    steps:
      - checkout
      - restore_cache:
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
      - run:
          name: Chmod permissions
          command: chmod +x gradlew
      - run:
          name: Download Dependencies
          command: ./gradlew androidDependencies
      - save_cache:
          paths:
            - ~/.gradle
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
      - store_artifacts:
          path: app/build/reports
          destination: reports
      - store_test_results:
          path: app/build/test-results
      - run:
          name: Generate fabric config
          command: ./gradlew fabricProp
      - run:
          name: Build prod release app
          command: ./gradlew assembleProdRelease -PversionCode=$CIRCLE_BUILD_NUM
      - run:
          name: Upload DEVELOP PROD to Fabric Beta
          command: ./gradlew crashlyticsUploadDistributionProdRelease
      - run:
          name: Build dev release app
          command: ./gradlew assembleDevRelease -PversionCode=$CIRCLE_BUILD_NUM
      - run:
          name: Upload DEVELOP DEMO to Fabric Beta
          command: ./gradlew crashlyticsUploadDistributionDevRelease
workflows:
  version: 2
  build_app:
    jobs:
      - develop_build:
          filters:
            branches:
              only: develop

Upvotes: 2

Related Questions