Skip to content
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
Binary file modified .DS_Store
Binary file not shown.
Binary file modified mac/.DS_Store
Binary file not shown.
Binary file modified unix/.DS_Store
Binary file not shown.
6 changes: 5 additions & 1 deletion unix/docker/images/android/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ ARG JAVA_IMAGE=java-17

FROM ${JAVA_IMAGE}

RUN echo ${JAVA_IMAGE}

Choose a reason for hiding this comment

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

medium

This echo command appears to be a leftover from debugging and should be removed from the final Dockerfile to keep it clean.


ENV ANDROID_SDK_ROOT="/usr/local/android-sdk"
ENV PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/platform-tools

Expand All @@ -25,13 +27,15 @@ RUN yes | sdkmanager --licenses

RUN echo y | sdkmanager "tools" && \
echo y | sdkmanager "platform-tools" && \
echo y | sdkmanager "build-tools;35.0.0" && \
echo y | sdkmanager "build-tools;34.0.0" && \
echo y | sdkmanager "build-tools;33.0.2" && \
echo y | sdkmanager "build-tools;33.0.1" && \
echo y | sdkmanager "build-tools;32.1.0-rc1" && \
echo y | sdkmanager "build-tools;30.0.3"
Comment on lines 28 to 35

Choose a reason for hiding this comment

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

medium

To improve efficiency and readability, these chained sdkmanager commands can be consolidated into a single call. The sdkmanager tool supports installing multiple packages at once, which reduces the number of processes spawned during the build.

RUN echo y | sdkmanager "tools" "platform-tools" "build-tools;35.0.0" "build-tools;34.0.0" "build-tools;33.0.2" "build-tools;33.0.1" "build-tools;32.1.0-rc1" "build-tools;30.0.3"


RUN echo y | sdkmanager "platforms;android-34" && \
RUN echo y | sdkmanager "platforms;android-35" && \
echo y | sdkmanager "platforms;android-34" && \
echo y | sdkmanager "platforms;android-33" && \
echo y | sdkmanager "platforms;android-32" && \
echo y | sdkmanager "platforms;android-31"
Comment on lines +37 to 41

Choose a reason for hiding this comment

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

medium

Similar to the previous comment, these sdkmanager calls can be combined into a single, more efficient command.

RUN echo y | sdkmanager "platforms;android-35" "platforms;android-34" "platforms;android-33" "platforms;android-32" "platforms;android-31"

86 changes: 86 additions & 0 deletions unix/docker/images/android/emulator-maestro/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Example build commands:
# $ docker build -t j17-android-emulator .
# $ docker build --build-arg ANDROID_IMAGE=j17-android -t j17-android-emulator .

# Example run commands:
# $ docker run -it -d -p 5900:5900 --name androidContainer -e VNC_PASSWORD=123 --privileged j17-android-emulator
# $ docker exec --privileged -it androidContainer bash -c "./start_vnc.sh"

# Java 21 Android image is default
ARG ANDROID_IMAGE=j21-android

FROM ${ANDROID_IMAGE}

# Avoid being asked interactive questions when installing packages
ARG DEBIAN_FRONTEND=noninteractive

# Install packages
RUN apt-get update && apt-get install -y \
bzip2 \
libdrm-dev \
libxkbcommon-dev \
libgbm-dev \
libasound-dev \
libnss3 \
libxcursor1 \
libpulse-dev \
libxshmfence-dev \
xauth \
xvfb \
x11vnc \
fluxbox \
wmctrl \
python3 \
python3-pip \
libdbus-glib-1-2 && \
rm -rf /var/lib/apt/lists/*

# Define emulator parameters
ARG ARCH=x86_64 \
TARGET=google_apis_playstore \
EMULATOR_API_LEVEL=34 \
EMULATOR_NAME="Pixel_7_Pro" \
EMULATOR_DEVICE="pixel_7_pro"

ENV EMULATOR_PACKAGE=system-images;android-${EMULATOR_API_LEVEL};${TARGET};${ARCH} \
EMULATOR_NAME=$EMULATOR_NAME \
EMULATOR_DEVICE=$EMULATOR_DEVICE \
ANDROID_AVD_HOME="/root/.android/avd"

# Install emulator tools
RUN sdkmanager "${EMULATOR_PACKAGE}" "emulator"

# List possible devices
RUN avdmanager list device

# Create required emulator AVD
RUN echo "no" | avdmanager create avd --force --name "${EMULATOR_NAME}" --device "${EMULATOR_DEVICE}" --package "${EMULATOR_PACKAGE}"

COPY . /

# Add permissions for emulator launch scripts ans VNC start script
RUN chmod a+x /emu_scripts/start_emu_headless.sh && \
chmod a+x /emu_scripts/start_emu.sh && \
chmod a+x /emu_scripts/start_vnc.sh

# Add script and emulator to the PATH
ENV PATH=$PATH:/emu_scripts:$ANDROID_SDK_ROOT/emulator

# Install pip
RUN pip3 install virtualenv

# Install Maestro
ENV MAESTRO_VERSION 1.41.0

RUN mkdir -p /opt/maestro && \
wget -q -O /tmp/${MAESTRO_VERSION} "https://github.com/mobile-dev-inc/maestro/releases/download/cli-${MAESTRO_VERSION}/maestro.zip" && \
unzip -q /tmp/${MAESTRO_VERSION} -d /opt/ && \
rm /tmp/${MAESTRO_VERSION}
ENV PATH=/opt/maestro/bin:${PATH}

# Install fonts for Maestro recording
RUN apt-get update && apt-get install -y \
fonts-noto \
fonts-noto-mono \
fonts-noto-color-emoji && fc-cache -f -v
Comment on lines +82 to +85

Choose a reason for hiding this comment

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

high

This RUN instruction has two issues:

  1. It runs apt-get update again, which is inefficient. It's better to combine package installations into a single RUN layer with one apt-get update call (like the one on line 18).
  2. It's missing rm -rf /var/lib/apt/lists/* after apt-get install, which will unnecessarily increase the Docker image size.

I recommend moving the font installation to the RUN block at line 18 and removing this block.


Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash

BL='\033[0;34m'
G='\033[0;32m'
RED='\033[0;31m'
YE='\033[1;33m'
NC='\033[0m' # No Color


emulator_name=${EMULATOR_NAME}

Choose a reason for hiding this comment

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

medium

This variable assignment is redundant. You can use the environment variable ${EMULATOR_NAME} directly in the script (e.g., on line 14) to simplify the code.


function launch_emulator() {
adb devices | grep emulator | cut -f1 | xargs -I {} adb -s "{}" emu kill
options="@${emulator_name} -no-boot-anim"

if [[ "$OSTYPE" == *linux* ]]; then
echo "${OSTYPE}: emulator ${options} -gpu off"
nohup emulator $options -gpu off &
fi
if [[ "$OSTYPE" == *darwin* ]] || [[ "$OSTYPE" == *macos* ]]; then
echo "${OSTYPE}: emulator ${options} -gpu swiftshader_indirect"
nohup emulator $options -gpu swiftshader_indirect &
fi

if [ $? -ne 0 ]; then
echo "Error launching emulator"
return 1
fi
Comment on lines +25 to +28

Choose a reason for hiding this comment

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

medium

This check if [ $? -ne 0 ] will not correctly determine if the emulator failed to launch. The nohup ... & command backgrounds the process and returns an exit code of 0 almost immediately. This check is misleading and provides a false sense of error handling.

}

function check_emulator_status () {
printf "${G}==> ${BL}Checking emulator booting up status 🧐${NC}\n"
start_time=$(date +%s)
spinner=( "" "" "" "" "" "" "" "" )
i=0
# Get the timeout value from the environment variable or use the default value of 300 seconds (5 minutes)
timeout=${EMULATOR_TIMEOUT:-300}

while true; do
result=$(adb shell getprop sys.boot_completed 2>&1)

if [ "$result" == "1" ]; then
printf "\e[K${G}==> \u2713 Emulator is ready : '$result' ${NC}\n"
adb devices -l
adb shell input keyevent 82
break
elif [ "$result" == "" ]; then
printf "${YE}==> Emulator is partially Booted! 😕 ${spinner[$i]} ${NC}\r"
else
printf "${RED}==> $result, please wait ${spinner[$i]} ${NC}\r"
i=$(( (i+1) % 8 ))
fi

current_time=$(date +%s)
elapsed_time=$((current_time - start_time))
if [ $elapsed_time -gt $timeout ]; then
printf "${RED}==> Timeout after ${timeout} seconds elapsed 🕛.. ${NC}\n"
break
fi
sleep 4
done
};

function disable_animation() {
adb shell "settings put global window_animation_scale 0.0"
adb shell "settings put global transition_animation_scale 0.0"
adb shell "settings put global animator_duration_scale 0.0"
}

launch_emulator
sleep 2
check_emulator_status
sleep 1
disable_animation
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/bin/bash

BL='\033[0;34m'
G='\033[0;32m'
RED='\033[0;31m'
YE='\033[1;33m'
NC='\033[0m' # No Color


emulator_name=${EMULATOR_NAME}

Choose a reason for hiding this comment

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

medium

This variable assignment is redundant. You can use the environment variable ${EMULATOR_NAME} directly in the script (e.g., on line 39) to simplify the code.


function check_hardware_acceleration() {
if [[ "$HW_ACCEL_OVERRIDE" != "" ]]; then
hw_accel_flag="$HW_ACCEL_OVERRIDE"
else
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS-specific hardware acceleration check
HW_ACCEL_SUPPORT=$(sysctl -a | grep -E -c '(vmx|svm)')
else
# generic Linux hardware acceleration check
HW_ACCEL_SUPPORT=$(grep -E -c '(vmx|svm)' /proc/cpuinfo)
fi

if [[ $HW_ACCEL_SUPPORT == 0 ]]; then
hw_accel_flag="-accel off"
else
hw_accel_flag="-accel on"
fi
fi

echo "$hw_accel_flag"
}

# NOT IN USE ATM.
hw_accel_flag=$(check_hardware_acceleration)
Comment on lines +12 to +35

Choose a reason for hiding this comment

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

medium

This function check_hardware_acceleration and its call are marked as "NOT IN USE ATM.". This dead code should be removed to improve readability and maintainability.


function launch_emulator () {
adb devices | grep emulator | cut -f1 | xargs -I {} adb -s "{}" emu kill
options="@${emulator_name} -no-window -no-boot-anim"

if [[ "$OSTYPE" == *linux* ]]; then
echo "${OSTYPE}: emulator ${options} -gpu off"
nohup emulator $options -gpu off &
fi
if [[ "$OSTYPE" == *darwin* ]] || [[ "$OSTYPE" == *macos* ]]; then
echo "${OSTYPE}: emulator ${options} -gpu swiftshader_indirect"
nohup emulator $options -gpu swiftshader_indirect &
fi

if [ $? -ne 0 ]; then
echo "Error launching emulator"
return 1
fi
Comment on lines +50 to +53

Choose a reason for hiding this comment

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

medium

This check if [ $? -ne 0 ] will not correctly determine if the emulator failed to launch. The nohup ... & command backgrounds the process and returns an exit code of 0 almost immediately. This check is misleading and provides a false sense of error handling.

}

function check_emulator_status () {
printf "${G}==> ${BL}Checking emulator booting up status 🧐${NC}\n"
start_time=$(date +%s)
spinner=( "" "" "" "" "" "" "" "" )
i=0
# Get the timeout value from the environment variable or use the default value of 300 seconds (5 minutes)
timeout=${EMULATOR_TIMEOUT:-300}

while true; do
result=$(adb shell getprop sys.boot_completed 2>&1)

if [ "$result" == "1" ]; then
printf "\e[K${G}==> \u2713 Emulator is ready : '$result' ${NC}\n"
adb devices -l
adb shell input keyevent 82
break
elif [ "$result" == "" ]; then
printf "${YE}==> Emulator is partially Booted! 😕 ${spinner[$i]} ${NC}\r"
else
printf "${RED}==> $result, please wait ${spinner[$i]} ${NC}\r"
i=$(( (i+1) % 8 ))
fi

current_time=$(date +%s)
elapsed_time=$((current_time - start_time))
if [ $elapsed_time -gt $timeout ]; then
printf "${RED}==> Timeout after ${timeout} seconds elapsed 🕛.. ${NC}\n"
break
fi
sleep 4
done
};

function disable_animation() {
adb shell "settings put global window_animation_scale 0.0"
adb shell "settings put global transition_animation_scale 0.0"
adb shell "settings put global animator_duration_scale 0.0"
};

function hidden_policy() {
adb shell "settings put global hidden_api_policy_pre_p_apps 1;settings put global hidden_api_policy_p_apps 1;settings put global hidden_api_policy 1"
};


launch_emulator
sleep 2
check_emulator_status
sleep 1
disable_animation
sleep 1
hidden_policy
sleep 1

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/bin/bash

readonly G_LOG_I='[INFO]'
readonly G_LOG_W='[WARN]'
readonly G_LOG_E='[ERROR]'
BL='\033[0;34m'
G='\033[0;32m'
NC='\033[0m' # No Color

main() {
launch_xvfb
launch_window_manager
run_vnc_server
printf "${G}==> ${BL}Welcome to android-emulator VNC by amrsa ${G}<==${NC}""\n"
}

launch_xvfb() {
# Set defaults if the user did not specify envs.
export DISPLAY=${XVFB_DISPLAY:-:1}
local screen=${XVFB_SCREEN:-0}
local resolution=${XVFB_RESOLUTION:-1280x1024x24}
local timeout=${XVFB_TIMEOUT:-5}

# Start and wait for either Xvfb to be fully up or we hit the timeout.
Xvfb ${DISPLAY} -screen ${screen} ${resolution} &
local loopCount=0
until xdpyinfo -display ${DISPLAY} > /dev/null 2>&1
do
loopCount=$((loopCount+1))
sleep 1
if [ ${loopCount} -gt ${timeout} ]
then
echo "${G_LOG_E} xvfb failed to start."
exit 1
fi
done
}

launch_window_manager() {
local timeout=${XVFB_TIMEOUT:-5}

# Start and wait for either fluxbox to be fully up or we hit the timeout.
fluxbox &
local loopCount=0
until wmctrl -m > /dev/null 2>&1
do
loopCount=$((loopCount+1))
sleep 1
if [ ${loopCount} -gt ${timeout} ]
then
echo "${G_LOG_E} fluxbox failed to start."
exit 1
fi
done
}

run_vnc_server() {
local passwordArgument='-nopw'

if [ -n "${VNC_PASSWORD}" ]
then
local passwordFilePath="${HOME}/x11vnc.pass"
if ! x11vnc -storepasswd "${VNC_PASSWORD}" "${passwordFilePath}"
then
echo "${G_LOG_E} Failed to store x11vnc password."
exit 1
fi
passwordArgument=-"-rfbauth ${passwordFilePath}"

Choose a reason for hiding this comment

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

critical

There's a critical bug here. The extra hyphen in passwordArgument=-'-rfbauth ...' will cause the argument to be passed incorrectly to x11vnc, which will likely prevent the VNC server from starting correctly with password authentication.

Suggested change
passwordArgument=-"-rfbauth ${passwordFilePath}"
passwordArgument="-rfbauth ${passwordFilePath}"

echo "${G_LOG_I} The VNC server will ask for a password."
else
echo "${G_LOG_W} The VNC server will NOT ask for a password."
fi

x11vnc -ncache_cr -display ${DISPLAY} -forever ${passwordArgument} &
wait $!
}


control_c() {
echo ""
exit
}

trap control_c SIGINT SIGTERM SIGHUP

main

exit
6 changes: 3 additions & 3 deletions unix/docker/images/gradle+kotlin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ ARG ANDROID_IMAGE=j17-android

FROM ${ANDROID_IMAGE}

ENV KOTLIN_VERSION 1.9.21
ENV KOTLIN_COMPILER kotlin-native-prebuilt-linux-x86_64-${KOTLIN_VERSION}
ENV KOTLIN_VERSION 2.2.0
ENV KOTLIN_COMPILER kotlin-native-prebuilt-${KOTLIN_VERSION}-linux-x86_64

RUN wget "https://download.jetbrains.com/kotlin/native/builds/releases/${KOTLIN_VERSION}/linux-x86_64/${KOTLIN_COMPILER}.tar.gz" -q --show-progress --progress=bar:force 2>&1 &&\
RUN wget "https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-native-prebuilt/${KOTLIN_VERSION}/${KOTLIN_COMPILER}.tar.gz" -q --show-progress --progress=bar:force 2>&1 &&\
mkdir -p /root/.konan/${KOTLIN_COMPILER} &&\
tar -xzvf ${KOTLIN_COMPILER}.tar.gz -C /root/.konan &&\
rm ${KOTLIN_COMPILER}.tar.gz
Expand Down
Loading