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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Documentation] How to install app via .apk file #251

Open
lsaadeh opened this issue Jul 11, 2020 · 6 comments
Open

[Documentation] How to install app via .apk file #251

lsaadeh opened this issue Jul 11, 2020 · 6 comments

Comments

@lsaadeh
Copy link

lsaadeh commented Jul 11, 2020

馃挰 Questions and Help

Please make sure that it is an issue / a feature request. If it is a question / help wanted, please visit our group chat. Thank you!

How to install app via .apk file

@arthuRHD
Copy link

arthuRHD commented Jul 29, 2020

You can use Android Debug Bridge CLI to push your apk inside your device, and install it from your local machine

adb -P 5037 [ -s %UDID_IF_MULTIPLE_DEVICE% ] push /path/to/local.apk /data/local/tmp/downloaded.apk
adb -P 5037 [ -s %UDID_IF_MULTIPLE_DEVICE% ] shell pm install -r /data/local/tmp/downloaded.apk

@archenroot
Copy link

@arthuRHD - imagine I have CICD pipeline:

  1. in some repo apk app is release
  2. trigger is started which should completely rebuild emulator with this new app installed and automatically started on docker start so its immediatelly available on web screen.

Can I pack emulater with this apk, install and start it on docker-andorid redeploy on kubernetes cluster?

I am new to android emulators, so thx for patience. 馃憤

@gainskills
Copy link

refer to #180

install in this way?
adb connect 34.68.174.199:5555
adb -e install /SuperSU_v2.79.apk

@cuttingedge1109
Copy link

refer to #180

install in this way? adb connect 34.68.174.199:5555 adb -e install /SuperSU_v2.79.apk

I installed an apk using this command inside the container.

androidusr@15be855c644c:~$ adb -e install /tmp/test.apk 
Performing Streamed Install
Success

But I cannot find it on the emulator UI.

@Banzaika
Copy link

@gainskills tell me please, how you are connecting adb to android container?! 馃ズ 馃檹

@Rodyb
Copy link

Rodyb commented Jun 9, 2024

For people coming here looking for answer on how to install an apk. @Banzaika

I used a docker-compose example made by: bernatvadell (credit where credit is due)
#395

I added an extra container that does the apk installation.
A script will run and poll the device if it's started, if it's started it will try to install the apk into the android-container.
This way the container directly has the apk you want.

docker-compose


services:
  android-container:
    build:
      context: .
    container_name: android-container
    privileged: true
    environment:
      - EMULATOR_DEVICE=Samsung Galaxy S10
      - WEB_VNC=true
      - WEB_LOG=true
      - WEB_LOG_PORT=9000
      - ENV_LOG_PATH=/var/log/
    volumes:
      - data:/home/androidusr
      - root:/root
    ports:
      - "6080:6080"
      - "9005:9000"
    devices:
      - "/dev/kvm:/dev/kvm"
    restart: always

  apk-installer:
    build:
      context: .
      dockerfile: Dockerfile_apk
    container_name: apk-installer
    depends_on:
      - android-container
    environment:
      - ANDROID_CONTAINER_NAME=android-container
      - APK_PATH=/apk/test_apk.apk
    entrypoint: ["/bin/bash", "-c", "/install-apk.sh"]
    restart: "no"

volumes:
  data:
  root:

Dockerfile

FROM budtmo/docker-android:emulator_11.0

USER root

RUN echo 'root:x:0:0:root:/root:/bin/bash' >> /etc/passwd

USER androidusr

COPY run.sh /run.sh

ENTRYPOINT ["/bin/bash", "-c"]
CMD ["/run.sh"]

Dockerfile_apk


RUN apt-get update && apt-get install -y adb netcat

COPY install-apk.sh /install-apk.sh
COPY test_apk.apk /apk/test_apk.apk
RUN chmod +x /install-apk.sh

install-apk.sh

#!/bin/bash

# Wait for the Android container to be ready
while ! nc -z ${ANDROID_CONTAINER_NAME} 5555; do
  echo "Waiting for Android container to be ready..."
  sleep 5  # 5 seconds
done

echo "Android container is ready."

# Connect to the Android emulator
adb connect ${ANDROID_CONTAINER_NAME}:5555

# Wait for the device to be online
DEVICE_ONLINE="offline"
while [ "$DEVICE_ONLINE" == "offline" ]; do
  DEVICE_ONLINE=$(adb -s ${ANDROID_CONTAINER_NAME}:5555 get-state 2>/dev/null)
  if [ "$DEVICE_ONLINE" == "offline" ]; then
    echo "Waiting for device to be online..."
    sleep 5  
  fi
done

echo "Device is online."

# Wait for the device to be fully booted
BOOT_COMPLETED="0"
while [ "$BOOT_COMPLETED" != "1" ]; do
  BOOT_COMPLETED=$(adb -s ${ANDROID_CONTAINER_NAME}:5555 shell getprop sys.boot_completed 2>/dev/null)
  if [ "$BOOT_COMPLETED" != "1" ]; then
    echo "Waiting for device to boot..."
    sleep 30  # 30 seconds
  fi
done

echo "Device booted successfully."

# Install the APK
adb -s ${ANDROID_CONTAINER_NAME}:5555 install ${APK_PATH}

echo "APK installation complete"

run.sh

#!/bin/bash
rm -rf /home/androidusr/emulator/*.lock
/home/androidusr/docker-android/mixins/scripts/run.sh

Result
Screenshot 2024-06-09 at 20 28 43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants