Gitlab CI - Android Sdk tools? - android

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/

Related

Android Command line tools sdkmanager always shows: Warning: Could not create settings

I use the new command line tools for Android because the old sdk-tools repository of Android isn't available anymore. So I changed my gitlab-ci to load the commandlintools. But when I try to run it I get the following error:
Warning: Could not create settings
java.lang.IllegalArgumentException
at com.android.sdklib.tool.sdkmanager.SdkManagerCliSettings.<init>(SdkManagerCliSettings.java:428)
at com.android.sdklib.tool.sdkmanager.SdkManagerCliSettings.createSettings(SdkManagerCliSettings.java:152)
at com.android.sdklib.tool.sdkmanager.SdkManagerCliSettings.createSettings(SdkManagerCliSettings.java:134)
at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:57)
at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
I already tried executing those commandy by hand, but I get the same error. Also if I run sdkmanager --version, the same error occurs.
My gitlab-ci looks like:
image: openjdk:9-jdk
variables:
ANDROID_COMPILE_SDK: "29"
ANDROID_BUILD_TOOLS: "29.0.3"
ANDROID_SDK_TOOLS: "6200805"
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/tools/bin/sdkmanager "platform-tools" "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
#- echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "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/tools/bin/sdkmanager --licenses
- set -o pipefail
stages:
- build
- test
lintDebug:
stage: build
script:
- ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint
assembleDebug:
stage: build
script:
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/
debugTests:
stage: test
script:
- ./gradlew -Pci --console=plain :app:testDebug
Instead of passing the argument --sdk_root for each single command execution, let's deep dive into the real cause.
Starting from Android SDK Command-line Tools 1.0.0 (6200805), in contrast to Android SDK 26.1.1 (4333796), the tools directory hierarchy has been changed.
Previously it was placed right inside ANDROID_HOME (which is deprecated, we will use the term ANDROID_SDK_ROOT for the rest of the paragraph), now it's still named as tools (the only thing you'll get after unpacking the downloaded commandlinetools zip file), but differently, you have to place it inside a directory called cmdline-tools on your own. The name cmdline-tools comes from its package name, where you can get from listing packages command sdkmanager --list, whose outputs include cmdline-tools;1.0 | 1.0 | Android SDK Command-line Tools.
Wrapping tools directory inside cmdline-tools directory would make it work, and help you get rid of the annoying --sdk_root argument. But what about the other parts?
Well, that's all you have to change. Let me explain more.
The king - sdkmanager lives inside cmdline-tools/tools/bin, you'd better set in PATH environment variable
cmdline-tools should not be set as ANDROID_SDK_ROOT. Because later, when updating Android SDK, or installing more packages, the other packages will be placed under ANDROID_SDK_ROOT, but not under cmdline-tools.
The final, complete ANDROID_SDK_ROOT directory structure should look like below, consist of quite a few sub-directories: build-tools, cmdline-tools, emulator, licenses, patcher, platform-tools, platforms, system-images. You can easily point out that build-tools and cmdline-tools are siblings, all sit inside the parent ANDROID_SDK_ROOT.
Let me recap in a simple way:
Set your preferred ANDROID_SDK_ROOT (just like before)
Download and unpack the commandlinetools zip file into a directory called cmdline-tools, which is inside ANDROID_SDK_ROOT
Append the directory $ANDROID_SDK_ROOT/cmdline-tools/tools/bin to environment variable PATH, so that the system knows where to find sdkmanager
!!UPDATE!!
The behavior has changed again since the build 6858069 (Android SDK Command-line Tools 3.0):
After unzipping the package, the top-most directory you'll get is cmdline-tools.
Rename the unpacked directory from cmdline-tools to tools, and place it under $ANDROID_SDK_ROOT/cmdline-tools, so now it should look like: $ANDROID_SDK_ROOT/cmdline-tools/tools. And inside it, you should have: NOTICE.txt bin lib source.properties. Actually according to the official Command-Line Tools doc, the tree structure should be android_sdk/cmdline-tools/version/bin/, but I've checked, using version or tools makes no difference here.
For your environment variable PATH, I would recommend you to set like this: PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/cmdline-tools/tools/bin, because after update later, you'll get the latest sdkmanager placed under $ANDROID_SDK_ROOT/cmdline-tools/latest/bin, put it in front will make it higher priority.
This appears to be a bug with the way sdkmanager locates the SDK installation folder.
A work-around is to set the flag --sdk_root. You can move ANDROID_HOME declaration higher, then use it with the subsequent commands.
- export ANDROID_HOME=$PWD/android-sdk-linux
- yes | android-sdk-linux/tools/bin/sdkmanager --sdk_root=${ANDROID_HOME} --licenses
- android-sdk-linux/tools/bin/sdkmanager --sdk_root=${ANDROID_HOME} "platform-tools" "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
Also, moved blanket license acceptance command to the first command to clean up the echo y parts.
Oddly enough if you run sdkmanager --sdk_root=${ANDROID_HOME} "tools" it will upgrade tools from 3.6.0 to 26.1.1 and sdkmanager no longer has this issue. This update takes time and bandwidth and isn't exactly necessary with the work-around.
For those who struggled with installing Android Command Line Tools for Appium on Windows 10/x64 just do as following:
Download latest Command line tools from android i.e. commandlinetools-win-6200805_latest.zip
Unzip the downloaded file
Create directory for storing commandline tools somewhere on your disk, with following path included: android/cmdline-tools/latest Basically when You unzip this Cmd line tools, just rename tools directory to latest and make sure You put this latest folder in android/cmdline-tools directory somewhere on your disk
Create ANDROID_HOME environment variable for directory that stores the cmdline tools directory location like:
C:\YourLocationWhereYouStoreTheDirectory\android\cmdline-tools\latest
Create new entry in Path environment variable as %ANDROID_HOME%\bin
The sdkmanager tries to figure out the android-sdk path based in where it's unpacked, without use the environment variables, like ANDROID_SDK_ROOT. But it's get worse, because it have a hard coded parent folder named cmdline-tools and if you unzip commandlinetools inside a folder with another name, it doesn't work, forcing us to use the parameter sdk_root to feed the inside variable correctly.
So, with that in mind we can use the following approach to solve this.
I will assume that we are using Ubuntu OS, so if you aren't, you should adapt some of that instructions.
Install Android-SDK.
sudo apt install android-sdk
After the instalation you will have a folder called android-sdk in /usr/lib
Create a folder called cdmline-tools inside the android-sdk folder
sudo mkdir /usr/lib/android-sdk/cmdline-tools
Download the Android command line tools zip from here (https://developer.android.com/studio?hl=en-419#downloads)
Unpack the file you just downloaded inside /usr/lib/android-sdk/cmdline-tools
sudo unzip /path/for/commandlinetools-linux-6200805_latest.zip -d /usr/lib/android-sdk/cmdline-tools
Go to you home dir and edit your .profile
nano .profile
Create an ANDROID_SDK_ROOT variable
export ANDROID_SDK_ROOT=/usr/lib/android-sdk
Put the sdkmanager folder in your path
export PATH=$ANDROID_SDK_ROOT/cmdline-tools/tools/bin:$PATH
Save and Exit
Reload you profile
. ~/.profile
Run
sdkmanager --version
You should see the version printed in your terminal.
Downloading the new cmdline-tools from Android Developer website requires the following directory structure to be respected.
Simple Solution:
Open Android Studio Tools Menu,
SDK Manager In the window that comes
up there are inner panels,
Choose SDK Tools panel Tick Android SDK Command-line Tools
Choose Apply button near the bottom of the window
Mixing responses from Jing Li and caller9, this is my script:
variables:
ANDROID_COMPILE_SDK: "29"
ANDROID_BUILD_TOOLS: "29.0.3"
ANDROID_SDK_TOOLS: "6200805"
before_script:
- apt-get update --yes
- apt-get install --yes wget tar unzip lib32stdc++6 lib32z1
- export ANDROID_HOME=${PWD}android-home
- install -d $ANDROID_HOME
- wget --output-document=$ANDROID_HOME/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip
- pushd $ANDROID_HOME
- unzip -d cmdline-tools cmdline-tools.zip
- popd
- export PATH=$PATH:${ANDROID_HOME}/cmdline-tools/tools/bin/
- sdkmanager --version
- set +o pipefail
- yes | sdkmanager --sdk_root=${ANDROID_HOME} --licenses
- set -o pipefail
- sdkmanager --sdk_root=${ANDROID_HOME} "platforms;android-${ANDROID_COMPILE_SDK}"
- sdkmanager --sdk_root=${ANDROID_HOME} "platform-tools"
- sdkmanager --sdk_root=${ANDROID_HOME} "build-tools;${ANDROID_BUILD_TOOLS}"
- export PATH=$PATH:${ANDROID_HOME}/platform-tools/
- chmod +x ./gradlew
[...]
I found the solution to use the latest command-line tools following those steps:
1 - Extracting the Command-line tools into a folder with this structure:
e.g.: $HOME/Development/android/cmdline-tools/latest
(this folder must contain lib, bin, notice.txt and source.properties)
2 - Defining ANDROID_HOME as an environment variable:
ANDROID_HOME="$HOME/Development/android/cmdline-tools/latest"
3 - Loading it on PATH:
PATH="$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/tools/lib:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools"
Got the same issue, came here by Google.
According to the AndroidStudio Archive, today was the release of 4.1.
I suppose that's no coincidence.
This completely unrelated guide has a hardlink for an older version of the sdk-tools for linux.
You can change the url to windows or mac for other OSs. I'll use that as a hotfix for now.
(that was supposed to be a comment not a solution)
Summarizing several useful posts here, and for people wanting a quick snippet, for example to plug in a Dockerfile, the following script is working for me:
RUN mkdir -p /opt/android/cmdline-tools/latest \
&& cd /opt/android/cmdline-tools/latest \
&& wget https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip \
&& bsdtar --strip-components=1 -xvf commandlinetools-linux-6858069_latest.zip \
&& yes | bin/sdkmanager --licenses \
&& bin/sdkmanager "build-tools;29.0.2" "platforms;android-29" \
&& rm commandlinetools-linux-6858069_latest.zip
It just requires bsdtar to be installed (it's usually packaged in popular distributions). Android platform/build tools version 29 are installed, and Android sdk root will be then located in /opt/android. While this setup works for me without warnings as it is, I have an issue when reinstalling packages already installed, or possibly installing different version of the packages: it clashes with packages already present and create bogus directories in the sdk root, with -2, -3 suffixes. These directories are then ignored, and warnings like Observed package id 'emulator' in inconsistent location are printed, so this behavior is definitely not desirable. If you have a fix for that please write it in the comments or, if you are confident enough, just edit the script with the exact fix.
Just solved this issue with IDE, looks pretty simple to me. (Actually this duplicate previous answer but with the picture). Just install sdk tools and everything should work.
I got the same error. After doing all solutions, i could not fix it. I solved this problem by reading: https://forum.unity.com/threads/android-build-not-working.844969/
Simplify an answer:
Opening sdkmanager.bat by notepad++
Changing this line from
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %SDKMANAGER_OPTS% -classpath "%CLASSPATH%" com.android.sdklib.tool.sdkmanager.SdkManagerCli %CMD_LINE_ARGS%
to
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %SDKMANAGER_OPTS% -classpath "%CLASSPATH%" com.android.sdklib.tool.sdkmanager.SdkManagerCli %CMD_LINE_ARGS% --sdk_root=%ANDROID_HOME%
(Note: Adding --sdk_root=%ANDROID_HOME% at the end
I would like to share my experience.
At first I try to explain why directory structure has to look
the way shown in this answer - https://stackoverflow.com/a/60460681/1758733 .
https://stackoverflow.com/users/668455/tristan asked for explanation several times so hope I will clarify
the situtation with the next experiment:
1. unpack cmdline-tools to any path, for example c:\Android\tools;
2. create a folder for SDK, let it be c:\Android\SDK;
3. install cmdline-tools (yes, we install cmdline-tools again =)):
c:\Android\tools\bin\sdkmanager --sdk_root=c:\Android\SDK "cmdline-tools;latest"
4. at this moment we can examine c:\Android\SDK and locate
the path c:\Android\SDK\cmdline-tools\latest. If we compare
this folder with the previous version c:\Android\tools we find out
that they are identical. The new installed c:\Android\SDK\cmdline-tools\latest\sdkmanager works
without --sdk_root argument so we could initially unpack cmdline-tools
to cmdline-tools\latest.
One may encounter another issue - Stuck at ".android/repositories.cfg could not be loaded."
Other issues & facts:
1. QtCreator works with another sdkmanager that placed in SDK_ROOT/tools/bin
2. SDK_ROOT/tools/bin/sdkmanager works only with JDK 8
3. Java uses its own storage for certificates and it's not convinient usually.
Thus one may want to use Windows certificate store. Unfortunately Grandle has the
issue - https://stackoverflow.com/a/59056537 - so use the following:
set JAVA_OPTS=-Djavax.net.ssl.trustStoreType=Windows-ROOT -Djavax.net.ssl.trustStore=NUL
To sum up the following recipe for development with Qt can be composed:
1. download commandlinetools-win-6200805_latest.zip
2. extract cmdline-tools so there will be hierarchy
SDKROOT
- cmdline-tools
- latest
- bin
- sdkmanager.bat
- ...
- lib
- ...
3. install JDK 8. set JAVA_HOME=c:\path\to\java so that %JAVA_HOME%/bin/java.exe exists.
4. set JAVA_OPTS=-Djavax.net.ssl.trustStoreType=Windows-ROOT -Djavax.net.ssl.trustStore=NUL
5. NDK may be downloaded manually or installed with sdkmanager
6. install required components:
SDKROOT\cmdline-tools\latest\bin\sdkmanager "tools" "build-tools;BUILD_TOOLS_VERSION" "platform-tools" "platforms;ANDROID_VERSION"
7. run qtcreator from console so JAVA_OPTS is taken into account (or set it globaly for windows user or even station)
8. tools -> options -> devices set paths to JDK 8, SDKROOT and NDK
This happened to me when downloading the standalone command line tools (commandlinetools-mac-6200805_latest) on a new Mac.
Based on all the answers here, I was able to make it work like this
# Define ANDROID_HOME, if not defined already
export ANDROID_HOME="~/Library/Android/sdk"
# Create the folder if missing
mkdir -p $ANDROID_HOME
# Let the tool know that it should use that SDK location.
sdkmanager --list --sdk_root=$ANDROID_HOME
The docs for the --sdk_root option say "Use the specified SDK root instead of the SDK containing this tool". This made me think that, despite being shipped standalone, the tool expects to be part of a bundle where the SDK is installed aswell.
Android SDK Tools now rest in following location: "android_sdk/cmdline-tools/version/bin/";
Therefore to solve this problem in Windows (same can be replicated in other OS), do the following:
Inside your android_sdk folder, create the folder: cmdline-tools and inside it create another folder: version extract / put all your files "/bin /lib NOTICE and sources.properties" files inside this version folder.
Set ANDROID_HOME to your android_sdk folder.
Add to your System Path: android_sdk\cmdlineAndroidSDK\cmdline-tools\version\bin\
Similarly, place your Android SDK Platform Tools inside your android_sdk/platform-tools/ and add corresponding PATH to ENVIRONMENTAL VARIABLES under System Variables
Based on updated suggestions from #Jing Li. Here's my version of gitlab-ci.yml
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "30"
ANDROID_BUILD_TOOLS: "29.0.2"
ANDROID_COMMAND_LINE_TOOLS: "6858069"
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
before_script:
- export GRADLE_USER_HOME=$(pwd)/.gradle
- chmod +x ./gradlew
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- mkdir -p android-sdk-linux/cmdline-tools
- export ANDROID_SDK_ROOT=$PWD/android-sdk-linux
- cd android-sdk-linux/cmdline-tools
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_COMMAND_LINE_TOOLS}_latest.zip
- unzip android-sdk.zip
- rm android-sdk.zip
- mv cmdline-tools version
- echo y | version/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
- echo y | version/bin/sdkmanager "platform-tools" >/dev/null
- echo y | version/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null
- export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools/
# temporarily disable checking for EPIPE error and use yes to accept all licenses
- set +o pipefail
- yes | version/bin/sdkmanager --licenses
- set -o pipefail
- cd ../../
- chmod +x ./gradlew
cache:
key: ${CI_PROJECT_ID}
paths:
- .gradle/
This page from Unity 2018 documentation also has a good explanation of resolving this issue, including such points like:
Installing the Android SDK without Android Studio.
Workaround for “Warning: Could not create settings” and “java.lang.IllegalArgumentException”
The trick for Android Studio version 3.6 or newer.
Warning about Java 9 or later, a JDK must be version 8.
https://docs.unity3d.com/2018.4/Documentation/Manual/android-sdksetup.html
Since new updates, there are some changes that are not mentioned in the documentation. After unzipping the command line tools package, the top-most directory you'll get is cmdline-tools. Rename the unpacked directory from cmdline-tools to tools, and place it under $C:/Android/cmdline-tools
now it will look like $C:/Android/cmdline-tools/tools
and it will work perfectly.
The first requirement of installing SDK (Any method) is to install Java & setting JAVA_HOME path.
Then, SDK command-line tools need installation path without which it throws NullPointerException.
To overcome this just pass the path where you want to install SDK with argument "--sdk_root"
Eg. sdkmanager.bat "platform-tools" "platforms;android-" --sdk_root=
If you are using Linux and at the same time, you don't want to mess your hands with complex workarounds, I recommend you to download and use the Snap version of sdkmanager.
Remember to use androidsdk instead of sdkmanager in the terminal.
Working Solution for Ubuntu using Android Studio
Here's the working procedure for Ubuntu and Debian like linux :
install Android studio as desribed in their website
https://developer.android.com/studio/install
run : flutter config --android-studio-dir <location of android studio> then flutter config --android-sdk /home/user/Android/Sdk (this is the default location of the SDK)
add the bin to your PATH PATH=$PATH:/home/user/Android/Sdk/tools/bin/
Afterwards, run : flutter doctor --android-licenses and accept all licences
To check if everything is ok run the doctor in verbos mode as following : flutter doctor -v
Here is very basic and simple solution
just change the folder structure
change main folder name to latest
then create a folder named cmdline-tools
create new folder inside cmdline called tools and put bin and other data inside tools folder
so it will look like this
user\latest\cmdline-tools\tools
I have searched alot but it worked for me
Android Studio is necessary when installing the command line tools even if it's not the editor you use to develop apps with. Unchecking the obsolete packages tab and downloading the tools should do it; that should clear the license issue and you can go back to your favorite IDE (such as VS Code).

Emulator: ERROR: detected a hanging thread 'QEMU1 main loop'. No response for 105001 ms

I use Gitlab CI for continuous integration. After every commit I have 3 jobs in the pipeline: debug, unitTests and instrumentedTests. But now instrumented tests failed because of the timeout. I added my gitlab-ci.yml file below
I've already tried downgrade android sdk versions, but no luck at all. Maybe there are some commands for yml-file that could fix the problem.
Also maybe somebody knows how to make all tests not failed for EMULATOR_VERSION > 22. 24 or higher never worked at all.
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "28"
ANDROID_BUILD_TOOLS: "28.0.3"
ANDROID_SDK_TOOLS: "4333796" # from https://developer.android.com/studio/#command-tools
EMULATOR_VERSION: "22"
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/sdk-tools-linux-${ANDROID_SDK_TOOLS}.zip
- unzip -d android-sdk-linux android-sdk.zip
- echo y | android-sdk-linux/tools/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "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/tools/bin/sdkmanager --licenses
- set -o pipefail
stages:
- build
- test
assembleDebug:
stage: build
script:
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/
unitTests:
stage: test
script:
- ./gradlew test
instrumentedTests:
stage: test
script:
- wget --quiet --output-document=android-wait-for-emulator https://raw.githubusercontent.com/travis-ci/travis-cookbooks/0f497eb71291b52a703143c5cd63a217c8766dc9/community-cookbooks/android-sdk/files/default/android-wait-for-emulator
- chmod +x android-wait-for-emulator
- android-sdk-linux/tools/bin/sdkmanager --update > update.log
- android-sdk-linux/tools/bin/sdkmanager "platform-tools" "emulator" "system-images;android-${EMULATOR_VERSION};default;armeabi-v7a" > installEmulator.log
- echo no | android-sdk-linux/tools/bin/avdmanager create avd -n test -k "system-images;android-${EMULATOR_VERSION};default;armeabi-v7a"
- android-sdk-linux/emulator/emulator -avd test -no-window -no-audio &
- ./android-wait-for-emulator
- adb shell input keyevent 82
- ./gradlew connectedCheck
There are following factors:
looks like google dropped support of qemu engine and only ranchu is supported for now
sdk was partially updated but there are bugs in update process
While qemu is no more supported this concrete bug with hanging seems wouldn't fixed ever.
For switch to ranchu environment:
avoid using *default* platform for avd's, prefer *google-api*'s one (while ranchu kernel is missed in default platforms)
update sdk with --channel=4
Just in case it helped me.

How to locate apk file using bitbucket-pipelines?

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

How to cache libs at Pipelines?

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

Git lab pipeline Android project

I create an android project in git lab. I'm trying to use pipelines .
The build failed with message
Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
How can I accept this licences automatically?
Adding --no-ui --all is not enough (I have already tried to add them!).
I tried all the soluctions presented [here](you need to accept the license agreements and complete) with no success.
Does someone actually managed to make git lab pipelines works for android?
Below my .gitlab-ci.yml file.
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "24"
ANDROID_BUILD_TOOLS: "25.0.3"
ANDROID_SDK_TOOLS: "25.0.3"
before_script:
- export ANDROID_HOME=$PWD/
- export PATH=$PATH:$PWD/
- 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/tools_r${ANDROID_SDK_TOOLS}-linux.zip
- unzip android-sdk.zip
- echo y | tools/android --silent update sdk --no-ui --all --filter android-${ANDROID_COMPILE_SDK}
- echo y | tools/android --silent update sdk --no-ui --all --filter platform-tools
- echo y | tools/android --silent update sdk --no-ui --all --filter build-tools-${ANDROID_BUILD_TOOLS}
- echo y | tools/android --silent update sdk --no-ui --all --filter extra-android-m2repository
- echo y | tools/android --silent update sdk --no-ui --all --filter extra-google-google_play_services
- echo y | tools/android --silent update sdk --no-ui --all --filter extra-google-m2repository
- chmod +x ./gradlew
stages:
- build
build:
stage: build
script:
- ./gradlew assembleDebug --stacktrace
artifacts:
paths:
- app/build/outputs/
The sdkmanager cli can be used to update sdks/ accept licenses.
To accept all licenses you can run
echo y | tools/bin/sdkmanager --licenses
I finnally resolve the problem using sdkmanager but I had to download the sdk zip instead of the tools zip like the code in my original question.
This is the final code I copied from Nick Petrovsky post on gitlab issue tracker
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "24"
ANDROID_BUILD_TOOLS: "25.0.3"
# ANDROID_SDK_TOOLS: "25.0.3"
ANDROID_SDK_TOOLS_REV: "3859397" # "26.0.1"
before_script:
- mkdir $HOME/.android # For sdkmanager configs
- echo 'count=0' > $HOME/.android/repositories.cfg # Avoid warning
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS_REV}.zip
- mkdir $PWD/android-sdk-linux
- unzip -qq android-sdk.zip -d $PWD/android-sdk-linux
- export ANDROID_HOME=$PWD/android-sdk-linux
- export ANDROID_NDK_HOME=$ANDROID_HOME/ndk-bundle # Remove if you don't need NDK
- export PATH=$PATH:$ANDROID_HOME/platform-tools/:$ANDROID_NDK_HOME
- echo y | $ANDROID_HOME/tools/bin/sdkmanager --update
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'tools'
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'platform-tools'
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'build-tools;'$ANDROID_BUILD_TOOLS
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'platforms;android-'$ANDROID_COMPILE_SDK
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'extras;android;m2repository'
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'extras;google;google_play_services'
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'extras;google;m2repository'
- chmod +x ./gradlew
At the end I used this gitlab-ci-android docker image
It is faster and cause much less problems:
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
- mkdir -p $GRADLE_USER_HOME
- chmod +x ./gradlew
cache:
paths:
- .gradle/wrapper
- .gradle/caches
build:
stage: build
script:
- ./gradlew assemble
test:
stage: test
script:
- ./gradlew check
I have created a CI image for Android, which can be found at https://gitlab.com/mvglasow/android-gitlab-ci.
It is based on what is described at https://about.gitlab.com/2018/10/24/setting-up-gitlab-ci-for-android-projects/, but it has all the Android tools in the image already so you don’t have to install them again for every CI run. Compared to the instructions, the image saves you about 30 seconds per pipeline.

Categories

Resources