Bitbucket pipeline can be configured for an Android project using following steps.
Step 1: Open "Pipelines" from left side of your repository page on bitbucket.
Step 2: Select "Java (Gradle)" from "Choose a language template" on new page opened.
Step 3: Select "commit" right bottom corner. Pic shown below:
Previous step will add "bitbucket-pipelines.yml" in the repository.
Step 4: Change file contents to
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: java:8 | |
pipelines: | |
default: | |
- step: | |
name: Build debug apk | |
#image: node:4.6.0 | |
script: | |
# Download and unzip android sdk | |
- wget https://dl.google.com/android/android-sdk_r24.4.1-linux.tgz | |
- tar zxvf android-sdk*.tgz | |
# Define android Home and add PATHs (After that you can run "android") | |
- export ANDROID_HOME="/opt/atlassian/pipelines/agent/build/android-sdk-linux" | |
- export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$PATH" | |
# Accept all licences http://stackoverflow.com/questions/38096225/automatically-accept-all-sdk-licences | |
- mkdir -p "$ANDROID_HOME/licenses" || true | |
- echo -e "\nd56f5187479451eabf01fb78af6dfcb131a6481e" > "$ANDROID_HOME/licenses/android-sdk-license" | |
- echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license" | |
# Update android sdk | |
- ( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) | android update sdk --no-ui --filter "extra-android-m2repository" -a | |
# Build apk | |
- chmod a+x gradlew | |
- ./gradlew assembleDebug | |
artifacts: | |
- app/build/outputs/apk/** | |
#- reports/*.txt |
Step 5: Replace license hash with hash stored in your android sdk's license folder. In my case license file is stored at
/home/swapnil/Android/Sdk/licenses
. Copy the hash stored in "android-sdk-license" file and paste it in place of "d56f5187479451eabf01fb78af6dfcb131a6481e". This step will ensure that, when pipeline downloads the sdk, its licenses will be automatically accepted and build will not fail.
Apk can be downloaded from artefacts tab shown in pipeline.