Google Android emulator howto
mouse 49 · person cloud · link
Last update
2020-08-05
2020
08-05
« — »
  1. We need to download cli tools then use sdkmanager to install the emulator and platform-tools.

    See also: fix sdkmanager Could not create settings to set the default sdk path.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    unzip -d /opt/android_sdk/cmdline-tools/ commandlinetools-linux-*.zip
    
    cd /opt/android_sdk/cmdline-tools/tools/bin
    
    ./sdkmanager --list
    ./sdkmanager platform-tools # install adb, fastboot
    ./sdkmanager emulator       # install the emulator
    
    ./sdkmanager --update       # update all installed packages to latest version
    
  2. Next we use avdmanager to create an Android Virtual Device for the emulator.

    See also: ARM on x86 support, androi API versions table, config.ini properties

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    cd /opt/android_sdk/cmdline-tools/tools/bin
    
    # choose a device definition for "-d" parameter (optional)
    ./avdmanager list | grep Nexus\ 5X    # => 10
    
    # choose and download a system image
    ./sdkmanager --list | grep "system-images;android-28.*X86_ARM"
    ./sdkmanager "platforms;android-24" \
                 "system-images;android-28;google_ndk;x86"
    
    # create virtual device with 6GB sdcard
    mkdir -p /opt/android_sdk/avd/ ~/.android/avd
    ./avdmanager delete avd -n nexus5x # eventually delete previous existing avd
    ./avdmanager create avd \
      -p /opt/android_sdk/avd/nexus5x \
      -n nexus5x -d 10 -c 6144M \
      -k "system-images;android-28;google_ndk;x86"
    
    ./avdmanager list avd
    
    # customize AVD
    cd /opt/android_sdk/avd/nexu5x
    sed -ri 's/PlayStore.enabled=no/PlayStore.enabled=yes/'                 config.ini
    sed -ri 's/disk.cachePartition.size=.+/disk.cachePartition.size=1024M/' config.ini
    sed -ri 's/disk.dataPartition.size=.+/disk.dataPartition.size=6144M/'   config.ini
    sed -ri 's/hw.keyboard=.+/hw.keyboard=yes/'                             config.ini
    sed -ri 's/hw.ramSize=.+/hw.ramSize=4096/'                              config.ini
    sed -ri 's/vm.heapSize=.+/vm.heapSize=2048/'                            config.ini
    sed -ri 's/sdcard.size=.+/sdcard.size=6144 MB/'                         config.ini
    
  3. run the emulator

    See also: opengapps.org, install playstore, emulator cli params

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    /opt/android_sdk/platform-tools/adb start-server
    
    cd /opt/android_sdk/emulator
    
    # check if acceleration is enabled
    ./emulator -accel-check
    adduser myusername kvm # logout & login
    
    # run emulator with "-writable-system" for gapps installation
    ./emulator -list-avds
    ./emulator -no-snapshot -writable-system @nexus5x
    
    # eventually install google apps & playstore
    # download "x86/9.0/stock" from https://opengapps.org/
    apt install lzip
    
    unzip -j open_gapps-*.zip 'Core/*'
    rm -f setup*
    lzip -d *.lz
    for i in *.tar; do tar -x --strip-components 2 -f $i; done
    rm -f *.tar
    
    alias adb=/opt/android_sdk/platform-tools/adb
    adb devices  # eventually use "-s device_id" in subsequent commands
    adb root
    adb remount
    
    adb push etc       /system
    adb push framework /system
    adb push app       /system
    adb push priv-app  /system
    
    adb shell stop
    adb shell start
    
    # close the emulator and re-run it normally
    ./emulator -no-snapshot @nexus5x
    
    /opt/android_sdk/platform-tools/adb kill-server