Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to setup Pipelines for an Android app

Deleted user October 13, 2016

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.

6 answers

1 accepted

17 votes
Answer accepted
Omkar January 12, 2018

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
xni06 January 20, 2018

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" ...)

 

Simon Barber January 23, 2018

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.

Deleted user January 23, 2018

Doh! Sorry and thanks @Simon Barber

Omkar January 23, 2018

Thanks @Simon Barber updated answer.

Nicholas Walsh June 21, 2018

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

SmsParser March 25, 2019

copy yml, change to api 28, error

The SDK directory '/opt/atlassian/pipelines/agent/build/D:\Android\sdk' does not exist.
Like aagamj likes this
3 votes
diniska September 4, 2018

I've found an article about Android + Pipelines integration: https://medium.com/rocknnull/setup-android-continuous-integration-ci-for-bitbucket-in-1-minute-9b72a4f1d745.

The `bitbucket-pipelines.yml` file looks pretty simple as a result of using Docker image `mingc/android-build-box`.

 

image: mingc/android-build-box:latest

pipelines:
    default:
        - step:
            caches:
                - gradle
            script:
                - chmod +x gradlew
                - ./gradlew assembleDebug

 

Nizamudeen Sherif July 1, 2019

But there is no APK present in ./gradlew or any of the folders in repo or artifacts list. Actually i want the downloadable APK in Artifacts list.

Like Nizamudeen Sherif likes this
1 vote
Melwin M October 23, 2016

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 August 30, 2017

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

 

Untitled.png

cripstian December 19, 2017

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
asbadve March 10, 2018

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

cripstian March 13, 2018

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.

0 votes
Moaz Rashad El Sayed Mohamed January 22, 2020

you can add 

before_script:
- touch local.properties


it will solve this issue.

0 votes
Malcolm Cooke December 5, 2018

Try using this docker image, which is a a standard ubuntu build pre-populated with android development environment

runmymind/docker-android-sdk:ubuntu-standalone

0 votes
Tory Adams September 12, 2017

dupliacte my fault. 

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events