here is my bitbucket-pipelines.yml file for android project:
# 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:
branches:
'{master}':
- 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-19"
- yes | sdkmanager "platforms;android-23"
- yes | sdkmanager "platforms;android-28"
- yes | sdkmanager "build-tools;27.0.3"
- yes | sdkmanager "build-tools;28.0.3"
- yes | sdkmanager "extras;android;m2repository"
- yes | sdkmanager "extras;google;m2repository"
- yes | sdkmanager "extras;google;instantapps"
- yes | sdkmanager --licenses
# Build apk
- echo “Start default step”
- # Add Android SDK license in the default file
- mkdir "${ANDROID_HOME}/licenses" || true
- echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > $ANDROID_HOME/licenses/android-sdk-license
- echo "d56f5187479451eabf01fb78af6dfcb131a6481e" > $ANDROID_HOME/licenses/android-sdk-license
# Build the app
- chmod a+x gradlew
- ./gradlew assembleDebug
- echo "Amazing"
definitions:
caches:
android-sdk: android-sdk
gradle: gradle
But when I rerun the script, then it always downloads libs for build:
Downloading https://services.gradle.org/distributions/gradle-4.4-all.zip
..............................................................................................
Unzipping /root/.gradle/wrapper/dists/gradle-4.4-all/9br9xq1tocpiv8o6njlyu5op1/gradle-4.4-all.zip to /root/.gradle/wrapper/dists/gradle-4.4-all/9br9xq1tocpiv8o6njlyu5op1
Set executable permissions for: /root/.gradle/wrapper/dists/gradle-4.4-all/9br9xq1tocpiv8o6njlyu5op1/gradle-4.4/bin/gradle
Starting a Gradle Daemon (subsequent builds will be faster)
Download https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.4/gradle-3.1.4.pom
Download https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.61/kotlin-gradle-plugin-1.2.61.pom
Download https://dl.google.com/dl/android/maven2/com/android/tools/build/bundletool/0.1.0-alpha01/bundletool-0.1.0-alpha01.pom
Download https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle-core/3.1.4/gradle-core-3.1.4.pom
Is any way to avoid redownload of libs for project, may be exist a case to cache and unzip them, like "android-sdk" and "gradle")?
Related
I use this Link for add gitlab CI in my android project. The CI work but I don't understand this part :
ANDROID_SDK_TOOLS: "4333796"
In the tutorial, android SDK tool is the last version available.
ANDROID_SDK_TOOLS is a little funny. It's what version of the command line tools we're going to download from the official site. So, that number really just comes from the latest version available there.
Installing packages.
But when click on the link, they send me in android studio download page.
How can i find the version code to put here ? Is it important to change it ?
I also tried with sdkmanager.bar --list in SDK > tool > bin directory
ERROR: JAVA_HOME is set to an invalid directory: D:\Software\JDK\openjdk-15_windows-x64_bin\jdk-15\bin
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
At the download page you'll find the "Command line tools only" section. The file name ends with the version number. As of now this is: 8092744 (it'll change in the future).
The name of the download URL and the zipped directory have been changed though, so you'll need to update your ci file accordingly. Using the template in the linked tutorial, the file could look like this (I only build a debug apk, you can add release versions too ofc, just like in the tutorial):
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "31"
ANDROID_BUILD_TOOLS: "29.0.2"
ANDROID_SDK_TOOLS: "8092744"
before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- 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
- echo y | android-sdk-linux/cmdline-tools/bin/sdkmanager --sdk_root=android-sdk-linux/cmdline-tools/latest/ "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
- echo y | android-sdk-linux/cmdline-tools/bin/sdkmanager --sdk_root=android-sdk-linux/cmdline-tools/latest/ "platform-tools" >/dev/null
- echo y | android-sdk-linux/cmdline-tools/bin/sdkmanager --sdk_root=android-sdk-linux/cmdline-tools/latest/ "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- chmod +x ./gradlew
# temporarily disable checking for EPIPE error and use yes to accept all licenses
- set +o pipefail
- yes | android-sdk-linux/cmdline-tools/bin/sdkmanager --sdk_root=android-sdk-linux/cmdline-tools/latest/ --licenses
- yes | android-sdk-linux/cmdline-tools/bin/sdkmanager --sdk_root=/builds/pauni/lara/android-sdk-linux --licenses
- set -o pipefail
stages:
- build
assembleDebug:
stage: build
script:
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/
I'm using BitBucket-pipelines for Android CI. I'm trying to export the artifact (generated apk) to the downloads section of the project.
My bitbucket-pipelines.yml is as follows, but it can't locate the apk file
image: openjdk: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
# Saving artifact
- curl -X POST "https://${BB_AUTH_STRING}#api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=#"**/*.apk"
definitions:
caches:
android-sdk: android-sdk
The issue is in
- curl -X POST "https://${BB_AUTH_STRING}#api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=#"**/*.apk"
I've also tried the following instead of **/*.apk
./app/build/outputs/apk/*.apk
But so far, nothing can locate the apk.
Has anyone faced this issue before? I'm just getting into CI with Android and would be grateful if someone could help.
I was able to resolve the issue by adding an artifacts tag after the build step. Then to publish the apk file I had to point to the specific file (path respective to the parent folder).
My bitbucket-pipelines.yml file is as follows now.
image: openjdk: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
artifacts:
- app/build/outputs/apk/debug/*.apk
- step:
script:
# Saving artifact
- curl -X POST "https://${BB_AUTH_STRING}#api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=#"app/build/outputs/apk/debug/app-debug.apk"
definitions:
caches:
android-sdk: android-sdk
You may use this command to export the latest apk
LATEST_APK=$(ls -lrt ./app/build/outputs/apk/debug/*.apk | tail -1 | awk -F" " '{ print $9 }')
and then the curl post command to upload it to downloads section of Bitbucket
curl -s -u "${BITBUCKET_REPO_OWNER}:${BB_AUTH_STRING}" -X POST "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" -F files=#"${LATEST_APK}" --verbose
I'm trying to use Travis CI in an Android repo and it's giving me a headache.
This is my .travis.yml file
sudo: required
jdk: oraclejdk8
language: android
android:
components:
# Uncomment the lines below if you want to
# use the latest revision of Android SDK Tools
# - tools
# - platform-tools
# The BuildTools version used by your project
- tools
- build-tools-26.0.2
- platform-tools
- tools
# The SDK version used to compile your project
- android-25
# Additional components
- extra-google-google_play_services
- extra-google-m2repository
- extra-android-m2repository
- extra-android-support
- addon-google_apis-google-25
# Specify at least one system image,
# if you need to run emulator(s) during your tests
- sys-img-armeabi-v7a-android-25
env:
global:
- API=25 # Android API level 25 by default
- TAG=google_apis # Google APIs by default, alternatively use default
- ABI=armeabi-v7a # ARM ABI v7a by default
- QEMU_AUDIO_DRV=none # Disable emulator audio to avoid warning
#- ANDROID_HOME=/usr/local/android-sdk-26.1.1 # Depends on the cookbooks version used in the VM
- TOOLS=${ANDROID_HOME}/tools # PATH order matters, exists more than one emulator script
- PATH=${ANDROID_HOME}:${ANDROID_HOME}/emulator:${TOOLS}:${TOOLS}/bin:${ANDROID_HOME}/platform-tools:${PATH}
- ADB_INSTALL_TIMEOUT=20 # minutes (2 minutes by default)
before_install:
- export EMULATOR="system-images;android-${API};${TAG};${ABI}" # Used to install/create emulator
- echo 'count=0' > /home/travis/.android/repositories.cfg # Avoid warning
- cd ./GimnasIO
- chmod +x gradlew
install:
- echo yes | sdkmanager "tools"
- echo yes | sdkmanager "platforms;android-25" # Latest platform required by SDK tools
- echo yes | sdkmanager "platforms;android-${API}" # Android platform required by emulator
- echo yes | sdkmanager "extras;android;m2repository"
- echo yes | sdkmanager "extras;google;m2repository"
- echo yes | sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2"
- echo yes | sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout-solver;1.0.2"
- echo yes | sdkmanager "$EMULATOR" # Install emulator system image
# Create and start emulator
- echo no | avdmanager create avd -n acib -k "$EMULATOR" -f --abi "$ABI" --tag "$TAG"
- emulator -avd acib -engine classic -no-window -verbose -qemu -m 512 &
before_script:
# Wait for emulator fully-booted and disable animations
- android-wait-for-emulator
- adb shell settings put global window_animation_scale 0 &
- adb shell settings put global transition_animation_scale 0 &
- adb shell settings put global animator_duration_scale 0 &
- adb shell input keyevent 82 &
script:
- ./gradlew build connectedCheck
after_script:
- cat ${TRAVIS_BUILD_DIR}/*/build/outputs/androidTest-results/connected/*
I have the ANDROID_HOME line commented because it was giving me an error and works fine without it apparently.
So, I looked up the problem and found that adding "android-wait-for-emulator" should work fine, but it doesn't. This is the first of the errors:
Unable to install /home/travis/build/.../app/build/outputs/apk/debug/app-debug.apk
com.android.ddmlib.InstallException: Unknown failure (Error: Could not access the Package Manager. Is the system running?)
Any idea why this keeps happening?
I have a problem with CircleCI that I can not get to work because my gradlew file is not in the root of my repository. As my depot is deprived here is a summary of his architectures:
root
-----> app_folder
------------> some folders
------------> some files
------------> gradlew
------> some files and folders
------> circle.yml
I tried to go into the app_folder folder using the cd command and change the path variable but nothing of it worked
circle.yml
#
# Build configuration for Circle CI
#
machine:
environment:
PATH: "~/$CIRCLE_PROJECT_REPONAME/app_folder:$PATH"
ANDROID_HOME: /usr/local/android-sdk-linux
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"'
_JAVA_OPTIONS: "-Xms512m -Xmx1024m"
ADB_INSTALL_TIMEOUT: "10"
ANDROID_API_LEVEL: 25
ANDROID_BUILD_TOOLS_VERSION: 25.0.2
java:
version: oraclejdk7
dependencies:
cache_directories:
- ~/.gradle
- ~/.android
- /usr/local/android-sdk-linux/extras
pre:
- if [ ! -d "$ANDROID_HOME/tools" ]; then echo y | android update sdk --no-ui --all --filter "tools"; fi
- if [ ! -d "$ANDROID_HOME/platforms/android-$ANDROID_API_LEVEL" ]; then echo y | android update sdk --no-ui --all --filter "android-$ANDROID_API_LEVEL"; fi
- if [ ! -d "$ANDROID_HOME/build-tools/$ANDROID_BUILD_TOOLS_VERSION" ]; then echo y | android update sdk --no-ui --all --filter "build-tools-$ANDROID_BUILD_TOOLS_VERSION"; fi
- if [ ! -d "$ANDROID_HOME/add-ons/addon-google_apis-google-$ANDROID_API_LEVEL" ]; then echo y | android update sdk --no-ui --all --filter "addon-google_apis-google-$ANDROID_API_LEVEL"; fi
- echo y | android update sdk --no-ui --all --filter "extra-google-m2repository"
- echo y | android update sdk --no-ui --all --filter "extra-google-google_play_services"
- echo y | android update sdk --no-ui --all --filter "extra-android-m2repository"
test:
override:
# start the emulator
- emulator -avd circleci-android24 -no-audio -no-window:
background: true
parallel: true
# wait for it to have booted
- circle-android wait-for-boot
# unlock the emulator screen
- sleep 30
- adb shell input keyevent 82
# run tests against the emulator.
- echo $PATH
- cd app_folder && .\gradlew connectedAndroidTest -PdisablePreDex
- .\\app_folder\\gradlew connectedAndroidTest -PdisablePreDex
- .\app_folder\\gradlew connectedAndroidTest -PdisablePreDex
- .\gradlew connectedAndroidTest -PdisablePreDex ~/github_name/app_folder
# copy the build outputs to artifacts
- cp -r app_folder/app/build/outputs $CIRCLE_ARTIFACTS
# copy the test results to the test results directory.
- cp -r app_folder/app/build/outputs/androidTest-results/* $CIRCLE_TEST_REPORTS
You just need to add this on the top :
general:
build_dir: your_folder
There's two options here. The quickest is to specify a custom build directory. Using your example, this would be:
general:
build_dir: app_folder
This is because per CircleCI Docs:
CircleCI will run its inference as well as all build commands from
that directory.
The second option would be to not rely on CircleCI's Inference commands at all and instead run everything, like Gradle yourself. You're already overriding the test phase, so you'd need to override the dependencies phase as well and run gradle dependencies yourself.
For example:
dependencies:
override:
- gradle --project-dir app_folder dependencies
-Ricardo N Feliciano
Developer Evangelist, CircleCI
I am using Travis CI to build my Android app, but I am dealing with build failure due to com.android.support.constraint:constraint-layout. I saw other questions but they didn't worked for me.
My .travis.yml file:
language: android
android:
components:
- tools
- tools #Running this twice get's the latest build tools (https://github.com/codepath/android_guides/wiki/Setting-up-Travis-CI)
- platform-tools
- android-24
- build-tools-25.0.0
- extra
- extra-google-google_play_services
- extra-google-m2repository
- extra-android-m2repository
- addon-google_apis-google-24
licenses:
- android-sdk-license-.+
- '.+'
jdk: oraclejdk8
sudo: required
script:
- chmod +x gradlew
- ./gradlew clean build
before_install:
- mkdir "$ANDROID_HOME/licenses" || true
- echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
- echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license"
And I am getting an error:
> Could not resolve all dependencies for configuration ':app:_debugApkCopy'.
> Could not find any matches for com.android.support.constraint:constraint-layout:+ as no versions of com.android.support.constraint:constraint-layout are available.
Searched in the following locations:
file:/usr/local/android-sdk/extras/android/m2repository/com/android/support/constraint/constraint-layout/maven-metadata.xml
file:/usr/local/android-sdk/extras/android/m2repository/com/android/support/constraint/constraint-layout/
file:/home/travis/build/*****/sdk-manager/com/android/support/constraint/constraint-layout/maven-metadata.xml
file:/home/travis/build/*****/sdk-manager/com/android/support/constraint/constraint-layout/
Required by:
project :app
Any idea how to solve this?
I think that you need to update tools after platform-tools due to codependencies like this:
android:
components:
- tools
- build-tools-25.0.2
- platform-tools
- tools
Try this simplified version of my related answer, if you install it via sdkmanager, it works, see 1 2 3.
language: android
jdk: oraclejdk8
sudo: required
android:
components: # Cookbooks version: https://github.com/travis-ci/travis-cookbooks/tree/9c6cd11
- tools # Update preinstalled tools from revision 24.0.2 to 24.4.1
- build-tools-25.0.2 # Match build-tools version used in build.gradle
- platform-tools # Update platform-tools to revision 25.0.3+
- tools # Update tools from revision 24.4.1 to 25.2.5
env:
global:
- API=25 # Android API level 25 by default
- TAG=google_apis # Google APIs by default, alternatively use default
- ABI=armeabi-v7a # ARM ABI v7a by default
- QEMU_AUDIO_DRV=none # Disable emulator audio to avoid warning
- ANDROID_HOME=/usr/local/android-sdk-24.0.2 # Depends on the cookbooks version used in the VM
- TOOLS=${ANDROID_HOME}/tools # PATH order matters, exists more than one emulator script
- PATH=${ANDROID_HOME}:${ANDROID_HOME}/emulator:${TOOLS}:${TOOLS}/bin:${ANDROID_HOME}/platform-tools:${PATH}
- ADB_INSTALL_TIMEOUT=20 # minutes (2 minutes by default)
before_install:
- export EMULATOR="system-images;android-${API};${TAG};${ABI}" # Used to install/create emulator
- echo 'count=0' > /home/travis/.android/repositories.cfg # Avoid warning
install:
# List and delete unnecessary components to free space
- sdkmanager --list || true
- sdkmanager --uninstall "system-images;android-15;default;armeabi-v7a"
# Update sdk tools to latest version and install/update components
- echo yes | sdkmanager "tools"
- echo yes | sdkmanager "platforms;android-25" # Latest platform required by SDK tools
- echo yes | sdkmanager "platforms;android-${API}" # Android platform required by emulator
- echo yes | sdkmanager "extras;android;m2repository"
- echo yes | sdkmanager "extras;google;m2repository"
- echo yes | sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2"
- echo yes | sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout-solver;1.0.2"
- echo yes | sdkmanager "$EMULATOR" # Install emulator system image
# Create and start emulator
- echo no | avdmanager create avd -n acib -k "$EMULATOR" -f --abi "$ABI" --tag "$TAG"
- emulator -avd acib -engine classic -no-window -verbose -qemu -m 512 &
before_script:
# Wait for emulator fully-booted and disable animations
- android-wait-for-emulator
- adb shell settings put global window_animation_scale 0 &
- adb shell settings put global transition_animation_scale 0 &
- adb shell settings put global animator_duration_scale 0 &
- adb shell input keyevent 82 &
script:
- ./gradlew build connectedCheck
after_script:
- cat ${TRAVIS_BUILD_DIR}/*/build/outputs/androidTest-results/connected/*
The simplest solution that worked for me was to copy the SDK licenses to my project from SDK and then tell Travis to copy them to itself while building.
There's already a closed issue for this on Travis's Github page and one of the mentioned solutions on it is definitely working currently.
Solution
Copy the licenses folder found in Android SDK's root directory.
Paste it in the root directory of your own project on the same hierarchy where .travis.yml file is.
Add these commands to your .travis.yml's before_install block:
.travis.yml:
before_install:
- mkdir "$ANDROID_HOME/licenses" || true
- cp ./licenses/* "$ANDROID_HOME/licenses/"
Exact link to solution: https://github.com/travis-ci/travis-ci/issues/6617#issuecomment-369580270
Link to my original answer on another SO question: https://stackoverflow.com/a/49050480/1402616