circleci / circleci-docs

Documentation for CircleCI.
https://circleci.com/docs/
Other
796 stars 1.3k forks source link

How to set up the gradle version of CI #8762

Closed Jay-57blocks closed 6 months ago

Jay-57blocks commented 6 months ago

Description

My CI used to work normally, but yesterday I discovered that it was built incorrectly. The CI used to build it using Gradle 8.5, but now he uses the latest Gradle 8.7 to build it, so an error occurred

I want to know how to set Gradle to version 8.5,and set Java version, the Java version used by CI is too new

image

Local computer environment (flutter doctor -v): On my computer, everything is fine

Flutter (Channel stable, 3.19.5, on macOS 14.4.1 23E224 darwin-arm64, locale en-CN)
    • Flutter version 3.19.5 on channel stable at /Users/57block/flutter_sdk/3.19.5
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 300451adae (6 weeks ago), 2024-03-27 21:54:07 -0500
    • Engine revision e76c956498
    • Dart version 3.3.3
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at /Users/57block/Library/Android/sdk
    • Platform android-34, build-tools 32.1.0-rc1
    • ANDROID_HOME = /Users/57block/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip

build.gradle

  dependencies {
        classpath 'com.android.tools.build:gradle:7.3.0'
    }

CI environment (flutter doctor -v):

Flutter (Channel stable, 3.19.5, on Ubuntu 22.04.4 LTS 6.5.0-1017-gcp, locale C.UTF-8)
    • Flutter version 3.19.5 on channel stable at /home/circleci/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 300451adae (6 weeks ago), 2024-03-27 21:54:07 -0500
    • Engine revision e76c956498
    • Dart version 3.3.3
    • DevTools version 2.31.1

 Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /opt/android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /opt/android/sdk
    • ANDROID_SDK_ROOT = /opt/android/sdk
    • Java binary at: /usr/lib/jvm/java-21-openjdk-amd64/bin/java
    • Java version OpenJDK Runtime Environment (build 21.0.2+13-Ubuntu-122.04.1)
    • All Android licenses accepted.

config.yml

version: 2.1

orbs:
  android: circleci/android@2.5.0
  flutter: circleci/flutter@2.0.4

jobs:  
  distribute_android:
    executor:
      name: android/android-machine
      resource-class: large
      tag: default
    parameters:
      flavor: # [qa, product]
        type: string
      track:  # [production, beta, alpha, internal]
        type: string
      release_status: # [completed, draft, halted, inProgress]
        type: string
        default: completed 
      package_name: 
        type: string
      google_play_json: 
        type: string
        default: $GOOGLE_PLAY_KEY
      segment_write_key:
        type: string
        default: $SEGMENT_WRITE_KEY_FLUTTER
    environment:
      GOOGLE_PLAY_KEY_PATH: play-store-credentials.json
      KEYSTORE_PROPERTIES_PATH: keystore.properties
      KEYSTORE_PATH: keystore.jks
    working_directory: ~/mobile-app-setup-tools
    steps:
      - checkout
      - flutter/install_sdk_and_pub:
          version: 3.19.5
      - flutter/install_android_gradle_dependencies
      - flutter/install_android_gem
      - run:
          name: "Install bundler"
          command: sudo gem install bundler
      - run:
          name: "Fastlane Deployment Android"
          command: |
            flutter doctor -v
            bundle exec fastlane upload_to_google_play_store flavor:<< parameters.flavor >> track:<< parameters.track >> release_status:<< parameters.release_status >> package_name:<< parameters.package_name >> segment_write_key:<< parameters.segment_write_key >> build_number:$BUILD_NUMBER json_path:$GOOGLE_PLAY_KEY_PATH smtp_user_name:$SMTP_PASSWORD smtp_password:$SMTP_USERNAME --verbose
          working_directory: android

workflows:
  test-release:
    jobs:
      - distribute_android:
          flavor: qa
          track: internal
          package_name: xxxx
          context:
            - mobile-app-testing
          filters:
            branches:
              only: testing-release     
rosieyohannan commented 6 months ago

Hello! In your config, for your executor you are specifying the default tag. As a first step I think specifying an image version would maybe solve your issue. If you take a look at this community post: https://discuss.circleci.com/t/android-images-2024q2-update/50872 that has details of what's changed in the latest image, which you are using. You can also check our developer hub image registry for details of the tags available. Does this help?

Jay-57blocks commented 6 months ago

@rosieyohannan I successfully executed the task using docker - image. I want to know how it is different from executor: settings. Please help me turn off this problem. Thank you

  distribute_android:
    docker:
      # Set to Gradle 8.5
      # https://circleci.com/developer/images/image/cimg/android
      - image: cimg/android:2023.12.1  
rosieyohannan commented 6 months ago

SO this part of your original config:

version: 2.1

orbs:
  android: circleci/android@2.5.0
  flutter: circleci/flutter@2.0.4

jobs:  
  distribute_android:
    executor:
      name: android/android-machine
      resource-class: large
      tag: default

shows you are using the machine executor that's defined in the android orb - more info here

Using a machine executor means you are building using a virtual machine. Using Docker means you are building using a Docker container.

So when you found things weren't working you were using the machine image with the default tag which is 2024.04.1 info here - this specifies Gradle 8.7.

But you found things are working using Docker because you're specifying an older image, 2023.12.1, which includes Gradle 8.5: https://hub.docker.com/layers/cimg/android/2023.12.1/images/sha256-de64e9240576fe5a030fe6129832c9444643598854801f66708a7ad6238858d7?context=explore

Does this help?

Jay-57blocks commented 6 months ago

@rosieyohannan I see, thank you, I will close the question