GitLab CI Configuration for Android Command Line Tools
When transitioning to the new Android Command Line Tools, you may encounter issues such as the "Warning: Could not create settings" error. This guide outlines a GitLab CI configuration that effectively sets up the Android environment for building and testing your applications.
GitLab CI Configuration
image: openjdk:9-jdk
variables:
ANDROID_COMPILE_SDK: "29"
ANDROID_BUILD_TOOLS: "29.0.3"
ANDROID_SDK_TOOLS: "6200805"
before_script:
# Update package list and install necessary packages
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
# Download and unzip the Android Command Line Tools
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip
- unzip -d android-sdk-linux android-sdk.zip
# Accept licenses and install required components
- echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null
# Set environment variables for the Android SDK
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
# Grant execute permissions to Gradle wrapper
- chmod +x ./gradlew
# Automatically accept licenses for SDK components
- set +o pipefail
- yes | android-sdk-linux/tools/bin/sdkmanager --licenses
- set -o pipefail
stages:
- build
- test
lintDebug:
stage: build
script:
- ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint
assembleDebug:
stage: build
script:
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/
debugTests:
stage: test
script:
- ./gradlew -Pci --console=plain :app:testDebug
Explanation of Key Sections
- Image: We use the
openjdk:9-jdkDocker image to ensure Java is available for building Android applications. - Variables: Define the SDK versions to be used in the build process.
- Before Script: This section installs necessary packages, downloads the Command Line Tools, and sets up the Android SDK environment.
- Stages: We define two stages:
buildandtest, which include linting, assembling the debug build, and running tests.
Common Issues
If you encounter the error Warning: Could not create settings, ensure that the Command Line Tools are correctly downloaded and that the environment variables are properly set. Running sdkmanager --version should not produce errors if everything is configured correctly.
By following this configuration, you should be able to set up your GitLab CI pipeline for Android development without issues.