Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Added fresh cmd-line tools and Android 12 #485

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions selenium/android/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ RUN \
x11vnc \
feh \
wmctrl \
libglib2.0-0 && \
libglib2.0-0 \
lib32stdc++6 && \
apt-get clean && \
rm -Rf /tmp/* && rm -Rf /var/lib/apt/lists/*

Expand All @@ -47,9 +48,9 @@ COPY fluxbox/aerokube.png /usr/share/images/fluxbox/
COPY --from=go /devtools/devtools /usr/bin/

# Android SDK
ENV ANDROID_HOME /opt/android-sdk-linux
ENV PATH /opt/android-sdk-linux/platform-tools:/opt/android-sdk-linux/tools:/opt/android-sdk-linux/tools/bin:/opt/android-sdk-linux/emulator:$PATH
ENV LD_LIBRARY_PATH ${ANDROID_HOME}/emulator/lib64:${ANDROID_HOME}/emulator/lib64/gles_swiftshader:${ANDROID_HOME}/emulator/lib64/qt/lib:${ANDROID_HOME}/emulator/lib64/vulkan:${LD_LIBRARY_PATH}
ENV ANDROID_SDK_ROOT /opt
ENV PATH $ANDROID_SDK_ROOT/cmdline-tools:$ANDROID_SDK_ROOT/cmdline-tools/tools/bin:$ANDROID_SDK_ROOT/tools:$ANDROID_SDK_ROOT/platform-tools:$ANDROID_SDK_ROOT/emulator:$PATH
ENV LD_LIBRARY_PATH ${ANDROID_SDK_ROOT}/emulator/lib64:${ANDROID_SDK_ROOT}/emulator/lib64/gles_swiftshader:${ANDROID_SDK_ROOT}/emulator/lib64/qt/lib:${ANDROID_SDK_ROOT}/emulator/lib64/vulkan:${LD_LIBRARY_PATH}
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64

ARG ANDROID_DEVICE=""
Expand All @@ -64,26 +65,27 @@ ARG SDCARD_SIZE="500"
ARG USERDATA_SIZE="500"

RUN \
curl -o sdk-tools.zip https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip && \
mkdir -p /opt/android-sdk-linux /root/.config/Android\ Open\ Source\ Project/ && \
unzip -q sdk-tools.zip -d /opt/android-sdk-linux && \
curl -o sdk-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip && \
mkdir -p /opt/cmdline-tools /root/.config/Android\ Open\ Source\ Project/ && \
unzip -q sdk-tools.zip -d /opt/cmdline-tools && \
mv /opt/cmdline-tools/cmdline-tools /opt/cmdline-tools/tools &&\
rm sdk-tools.zip && \
yes | sdkmanager --licenses

RUN \
sdkmanager "emulator" "tools" "platform-tools" "$BUILD_TOOLS" "platforms;$PLATFORM" "$EMULATOR_IMAGE" && \
sdkmanager "tools" "platform-tools" "$BUILD_TOOLS" "platforms;$PLATFORM" "$EMULATOR_IMAGE" && \
mksdcard "$SDCARD_SIZE"M sdcard.img && \
echo "no" | ( \
([ -n "$ANDROID_DEVICE" ] && avdmanager create avd -n "$AVD_NAME" -k "$EMULATOR_IMAGE" --abi "$ANDROID_ABI" --device "$ANDROID_DEVICE" --sdcard /sdcard.img ) || \
avdmanager create avd -n "$AVD_NAME" -k "$EMULATOR_IMAGE" --abi "$ANDROID_ABI" --sdcard /sdcard.img \
([ -n "$ANDROID_DEVICE" ] && avdmanager create avd -n "$AVD_NAME" -k "$EMULATOR_IMAGE" --abi "$ANDROID_ABI" --device "$ANDROID_DEVICE" --sdcard sdcard.img ) || \
avdmanager create avd -n "$AVD_NAME" -k "$EMULATOR_IMAGE" --abi "$ANDROID_ABI" --sdcard sdcard.img \
) && \
ldconfig && \
( \
resize2fs /root/.android/avd/$AVD_NAME.avd/userdata.img "$USERDATA_SIZE"M || \
/opt/android-sdk-linux/emulator/qemu-img resize -f raw /root/.android/avd/$AVD_NAME.avd/userdata.img "$USERDATA_SIZE"M \
/opt/emulator/qemu-img resize -f raw /root/.android/avd/$AVD_NAME.avd/userdata.img "$USERDATA_SIZE"M \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't get where emulator directory comes from.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't get where emulator directory comes from.

During building process i saw interesting logs:
=> => # Warning: Package "com.android.repository.impl.generated.v2.RemotePackage@863816ad" (emulator) should be installed in
=> => # "/opt/emulator" but
=> => # it already exists.
=> => # Installing in "/opt/emulator-2" instead.

And turned out that when you fetch system image e.g. sdkmanager "system-images;android-31;default;x86_64"

it automatically fetch emulator directory too.
So i decided remove fetch emulator directly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will these changes work for older Android versions?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting question)
What boundaries of supported versions need to test?
Because i'm not sure about backward compatibility of new SDK)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbudim at least Android 6.0+.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i'll check 6th and back with result)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've checked 6,7 versions - doesn't work, seems problem in vulkan drivers.
Need some free time for investigate this. Will do a bit later)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbudim sure

) && \
([ -z "$REPLACE_IMG" ] || mv /root/.android/avd/$AVD_NAME.avd/userdata.img /root/.android/avd/$AVD_NAME.avd/userdata-qemu.img ) && \
rm /opt/android-sdk-linux/system-images/$PLATFORM/$EMULATOR_IMAGE_TYPE/"$ANDROID_ABI"/userdata.img
rm /opt/system-images/$PLATFORM/$EMULATOR_IMAGE_TYPE/"$ANDROID_ABI"/userdata.img

COPY ["Emulator.conf", "/root/.config/Android Open Source Project/Emulator.conf"]
COPY emulator-snapshot.sh tmp/chromedriver* *.apk /usr/bin/
Expand Down
4 changes: 2 additions & 2 deletions selenium/android/android.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/opt/android-sdk-linux/emulator/lib64
/opt/android-sdk-linux/emulator/lib64/gles_swiftshader
/opt/emulator/lib64
/opt/emulator/lib64/gles_swiftshader
2 changes: 1 addition & 1 deletion selenium/android/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ if [ -n "$STOP" ]; then exit 0; fi
if [ "$ENABLE_VNC" != "true" ] && [ "$ENABLE_VIDEO" != "true" ]; then
EMULATOR_ARGS="$EMULATOR_ARGS -no-window"
fi
ANDROID_AVD_HOME=/root/.android/avd DISPLAY="$DISPLAY" /opt/android-sdk-linux/emulator/emulator ${EMULATOR_ARGS} -writable-system -no-boot-anim -no-audio -no-jni -avd @AVD_NAME@ -sdcard /sdcard.img -skin "$SKIN" -skindir /opt/android-sdk-linux/platforms/@PLATFORM@/skins/ -gpu swiftshader_indirect -ranchu -qemu -enable-kvm &
ANDROID_AVD_HOME=/root/.android/avd DISPLAY="$DISPLAY" /opt/emulator/emulator ${EMULATOR_ARGS} -writable-system -no-boot-anim -no-audio -no-jni -avd @AVD_NAME@ -sdcard sdcard.img -skin "$SKIN" -skindir /opt/platforms/@PLATFORM@/skins/ -gpu swiftshader_indirect -ranchu -qemu -enable-kvm &
EMULATOR_PID=$!

if [ "$ENABLE_VNC" == "true" ]; then
Expand Down
9 changes: 7 additions & 2 deletions selenium/automate_android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ validate_android_version(){
type=${2:-"default"}
abi=${3:-"x86"}
avd_name="android$version-1"
build_tools="build-tools;29.0.2"
build_tools="build-tools;31.0.0"
replace_img="y"
case "$version" in
4.4)
Expand Down Expand Up @@ -81,6 +81,11 @@ validate_android_version(){
emulator_image="system-images;android-30;$type;$abi"
replace_img=""
;;
12.0)
platform="android-31"
emulator_image="system-images;android-31;$type;$abi"
replace_img=""
;;
*)
echo "Unsupported Android version"
false
Expand Down Expand Up @@ -151,7 +156,7 @@ mkdir -p "$TMP_DIR"
cp android/entrypoint.sh "$TMP_DIR/entrypoint.sh"
cp -r ../static/chrome/devtools "$TMP_DIR/devtools"

appium_version=$(request_answer "Specify Appium version:" "1.18.1")
appium_version=$(request_answer "Specify Appium version:" "1.22.0")

until [ "$?" -ne 0 ]; do
android_image_type=$(request_answer "Specify Android image type (possible values: \"default\", \"google_apis\", \"google_apis_playstore\", \"android-tv\", \"android-wear\"):" "default")
Expand Down