Config for gitlab ci android with unit tests and instrumented tests
source link: https://gist.github.com/illuzor/988385c493d3f7ed7193a6e3ce001a68
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
HerHde commented Dec 15, 2018
Thank you very much for this CI conf!
I've tested it successfully with `EMULATOR_VERSION: "24", if you wanna take a look.
thank you so much , help me a lot !!
I'm seeing several places where running instrumentation tests in gitlab ci has emulator version 24. Is there any reason for this? The latest version of the emulator is on 29
Author
illuzor commented Jun 19, 2019
I'm seeing several places where running instrumentation tests in gitlab ci has emulator version 24. Is there any reason for this? The latest version of the emulator is on 29
Newer version may not start or may have problems with installing the application. But maybe something was changed on the gitlab ci.
You can try any version. Maybe it will work, maybe not.
Note:
this can help
#
- adb shell input tap 233 293
# Send keystroke Arrow Right
- sleep 3; adb shell input keyevent 22
# Send keystroke Arrow Right again
- sleep 3; adb shell input keyevent 22
# Send keystroke Enter to press a button on the dialog
- sleep 3; adb shell input keyevent 66
when happens something like this:
java.lang.RuntimeException: Waited for the root of the view hierarchy to have window focus and not request layout for 10 seconds. If you specified a non default root matcher, it may be picking a root that never takes focus
Just tried and it is actually not working, it is blocked on this step:
$ android-sdk-linux/emulator/emulator -avd test -no-window -no-audio &
$ ./android-wait-for-emulator
Author
illuzor commented Dec 10, 2019
@MTersigni I know about this problem. It`s caused by latest android emulator update. I am looking for a solution.
Gitlab ci is really strange. Instrumented tests may work good or not work at all depends on The Moon phase.
So my advice - use Robolectric. It s simple and much more faster than tests on an emulator or device.
This does not seem to work. It fails at android-sdk-linux/tools/bin/sdkmanager --update > update.log
with
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)
This does not seem to work. It fails at
android-sdk-linux/tools/bin/sdkmanager --update > update.log
withWarning: 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)
Any solution?
Author
illuzor commented Feb 10, 2021
This does not seem to work. It fails at
android-sdk-linux/tools/bin/sdkmanager --update > update.log
withWarning: 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)
Hi. DO you solved this bug?
Author
illuzor commented Jun 11, 2021
@edmooliveira29 the config is updated. Try this new version. Unit tests should work, but not sure about instrumented tests.
Also you can see another config for example.
@illuzor Are you still able to run it at the current moment?
Author
illuzor commented Oct 27, 2021
@adriano-silva no. I only have a config without instrumented tests.
williamobiana commented Nov 25, 2022 •
This is an updated version for the config of gitlab ci android with unit tests and instrumented tests
image: openjdk:11-jdk
variables:
ANDROID_COMPILE_SDK: "30"
ANDROID_BUILD_TOOLS: "30.0.3"
SDK_TOOLS: "8512546" # modify with latest version from https://developer.android.com/studio/#command-tools
EMULATOR_VERSION: "24"
before_script:
- apt-get --quiet update --yes
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/commandlinetools-linux-${SDK_TOOLS}_latest.zip
- unzip -q android-sdk.zip -d android-sdk-linux
- rm android-sdk.zip
# The hierarchy of the files have been changed, so you will have to re-arrange it
# ANDROID_HOME is deprecated, we will use ANDROID_SDK_ROOT
- export ANDROID_SDK_ROOT=$PWD/android-sdk-linux
# the current hierarchy is android-sdk-linux/cmdline-tools/tools (but the depenencies are not in the tools folder)
# move the necessary dependencies into the tools folder
- mv $ANDROID_SDK_ROOT/cmdline-tools/{lib,bin,source.properties,NOTICE.txt} $ANDROID_SDK_ROOT/cmdline-tools/tools
# create a latest folder that will have the updated version of the dependencies
- mkdir $ANDROID_SDK_ROOT/cmdline-tools/latest
# define PATH for all executable files we will run (skdmanger, avdmanager, abd, emulator)
- export PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/cmdline-tools/tools/bin:$ANDROID_SDK_ROOT/platform-tools:$ANDROID_SDK_ROOT/emulator
# sdkmanager is located in the tools/bin folder which we have specified in our PATH $ANDROID_SDK_ROOT/cmdline-tools/tools/bin
- sdkmanager --sdk_root=${ANDROID_SDK_ROOT} --update > update.log
- echo y | sdkmanager --sdk_root=${ANDROID_SDK_ROOT} "platforms;android-${ANDROID_COMPILE_SDK}" "build-tools;${ANDROID_BUILD_TOOLS}" "extras;google;m2repository" "extras;android;m2repository" > installPlatform.log
- chmod +x ./gradlew #if you are using a working directory, cd into it before running the gradlew command
stages:
- test
unitTests:
stage: test
script:
- ./gradlew test
instrumentedTests:
stage: test
script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes libx11-dev libpulse0 libgl1 libnss3 libxcomposite-dev libxcursor1 libasound2
- 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
- sdkmanager --update > update.log
- sdkmanager "platform-tools" "emulator" "system-images;android-${EMULATOR_VERSION};default;armeabi-v7a" > installEmulator.log
# create the emulator
- echo no | avdmanager create avd -n test -k "system-images;android-${EMULATOR_VERSION};default;armeabi-v7a"
# for some reasons the emulator doesnt start automatically, so we have to start it
- abd start-server
# run in the background without window and audio
- emulator -avd test -no-window -no-audio &
- ./android-wait-for-emulator
- adb shell input keyevent 82
- ./gradlew connectedCheck #or ./gradlew connectedAndroidTest
Ridje commented Dec 8, 2022
- echo y | sdkmanager --sdk_root=${NDROID_SDK_ROOT} "platforms;android-${ANDROID_COMPILE_SDK}" "build-tools;${ANDROID_BUILD_TOOLS}" "extras;google;m2repository" "extras;android;m2repository" > installPlatform.log
@williamobiana I suppose there should be ANDROID_SDK_ROOT instead of NDROID_SDK_ROOT
williamobiana commented Dec 8, 2022 •
Yes @Ridje , Typo has been corrected. Thanks
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK