How to setup Pipelines for an Android app

Is it possible to setup Pipelines to build an Android app? At the moment, I'm getting the following:

location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

 

I'm using the default config file at the moment as I can't find anything regarding Android builds.

# This is a sample build configuration for Gradle.
# Check our guides at https://confluence.atlassian.com/x/VYk8Lw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: java:8

pipelines:
  default:
    - step:
        script: # Modify the commands below to build your repository.
          - android update sdk --filter "build-tools-23.0.3" --no-ui -a   
          - ./gradlew build

 

Thanks.

3 answers

Hi, there is no android sdk preinstalled on Docker image java:8. So you can download and install the sdk manually. The following steps works with my pipeline.

But i think a better and much faster way is to use an prepared docker image like this: https://hub.docker.com/r/guptasanchit90/android-gradle/

Hope this helps:

image: java:8
pipelines:
  default:
    - step:
        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"
          - echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$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
vinayyam I'm New Here Aug 30, 2017

Hi, I did the above thing but I am facing error PFA

 

Untitled.png

Hope you solved it by now, but for anyone trying to use what Melwin wrote:

Please try replacing the HTML escaping characters like this from:

* >   =>  turns into `>`  (greater than)

* &  => turns into  '&'  (ampersant)

 

So in the end it looks like:

image: java:8
pipelines:
  default:
    - step:
        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"
          - echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$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

Download and run on latest sdk with sdkmanager.

# This is a sample build configuration for Java (Gradle).
# Check our guides at https://confluence.atlassian.com/x/zd-5Mw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: java:8

pipelines:
default:
- step:
caches:
- gradle
- android-sdk

script:
# Download and unzip android sdk
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip
- unzip -o -qq android-sdk.zip -d android-sdk

# Define Android Home and add PATHs
- export ANDROID_HOME="/opt/atlassian/pipelines/agent/build/android-sdk"
- export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"

# Download packages.
- yes | sdkmanager "platform-tools"
- yes | sdkmanager "platforms;android-27"
- yes | sdkmanager "build-tools;27.0.3"
- yes | sdkmanager "extras;android;m2repository"
- yes | sdkmanager "extras;google;m2repository"
- yes | sdkmanager "extras;google;instantapps"
- yes | sdkmanager --licenses

# Build apk
- chmod a+x ./gradlew
- ./gradlew assembleDebug

definitions:
caches:
android-sdk: android-sdk

Works a treat the first time but subsequent builds results in the following failure:

Screen Shot 2018-01-20 at 15.47.35.png

Cache "gradle": Downloading
Cache "gradle": Extracting
Cache "gradle": Extracted
Cache "android-sdk": Downloading
Cache "android-sdk": Extracting
Cache "android-sdk": Extracted
+ wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip

+ unzip -qq android-sdk.zip -d android-sdk
replace android-sdk/tools/bin/lint? [y]es, [n]o, [A]ll, [N]one, [r]ename: NULL
(EOF or read error, treating as "[N]one" ...)

 

Try add the option -o to the unzip command below:

- unzip -o -qq android-sdk.zip -d android-sdk

See the basic unzip command options below:

-f freshen existing files, create none
-n never overwrite existing files
-q quiet mode (-qq => quieter)
-o overwrite files WITHOUT prompting

The -qq is for quieter mode and the -o will overwrite files without prompting.

Hope this helps.

Thanks @Simon Barber updated answer.

dupliacte my fault. 

 

Suggest an answer

Log in or Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

661 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot