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

1 accepted

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.

The android-sdk was not being added to the cache. 

I had to update definition to: 

definitions:
caches:
android-sdk: /opt/atlassian/pipelines/agent/build/android-sdk

* Cache took time to update, If i wait it might have started working with just android-sdk

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

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

Its fail due to not accepting the licenses. Can you please give me cmd to do thatCapture.PNG

Try adding the content of the licences from your local machine.

Find the files in your `$ANDROID_HOME` to extract the content and put them in the appropriate  place inside your `bitybucket-pipelines.yml`.

`cat $ANDROID_HOME/licences/android-sdk-licence`

and

`cat $ANDROID_HOME/licences/android-sdk-preview-licence`

You should first find out where $ANDROID_HOME points.

After this you can replace them in your `bitbucket-pipelines.yml` file.

It may be that the licences from the example above are expired or something.

dupliacte my fault. 

 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 12, 2018 in Bitbucket

Do you use any Atlassian products for your personal projects?

After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...

29,190 views 26 12
Join discussion

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