Create emulator in Linux Virtual machine through terminal using docker for android

 Set Java:

1. Use Java 11 or 17 Instead of Java 18

SDK Manager works best with Java 11 or Java 17. Java 18 is not officially supported for Android SDK tools.

Run the following command to check your Java version:

java -version

sudo apt update
sudo apt install openjdk-17-jdk

export JAVA_HOME=$(/usr/libexec/java_home -v 17) export PATH=$JAVA_HOME/bin:$PATH

Now, try running the sdkmanager command again.

2. Install android image using sdkmanager

sdkmanager "system-images;android-34;google_apis;arm64-v8a" --sdk_root=/opt/android-sdk

if sdkmanger is not found in emulator

root@dee16e24c043:/# ${ANDROID_SDK_ROOT}/cmdline-tools/bin/sdkmanager --sdk_root=${ANDROID_SDK_ROOT} --licenses

3. Create emulator using avdmanager

avdmanager create avd -n MyEmulator -k "system-images;android-34;google_apis_playstore;x86_64" --device "pixel_5"

4. Launch the Emulator

root@dee16e24c043:/# emulator -avd MyEmulator -no-snapshot -noaudio -no-boot-anim

5. Install kvm if emulator not launched

sudo apt update

sudo apt install -y cpu-checker

kvm-ok

INFO: Your CPU does not support KVM extensions

KVM acceleration can NOT be used


Run the Emulator with Software Rendering (Slow Alternative)

emulator -avd MyEmulator -no-accel -gpu swiftshader




Error 1:

error "WARNING | File System is not ext4, disable QuickbootFileBacked feature ERROR | x86_64 emulation currently requires hardware acceleration! CPU acceleration status: KVM requires a CPU that supports vmx or svm More info on configuring VM acceleration on Linux: https://developer.android.com/studio/run/emulator-acceleration#vm-linux General information on acceleration: https://developer.android.com/studio/run/emulator-acceleration." when use "emulator -avd MyEmulator -no-snapshot -noaudio -no-boot-anim"


The error "x86_64 emulation currently requires hardware acceleration!" means that your system lacks the necessary hardware acceleration for running an x86-based Android emulator. Here's how to fix it:


1. Check If Your CPU Supports Virtualization

Run the following command to check if your CPU supports virtualization (VT-x for Intel, AMD-V for AMD):


egrep -c '(vmx|svm)' /proc/cpuinfo
  • If the output is 0, your CPU does not support virtualization, and you can't run the x86 emulator.
  • If the output is 1 or more, virtualization is supported, but it may not be enabled in BIOS.

2. Enable Virtualization in BIOS

If virtualization is supported but disabled:

  1. Restart your system and enter BIOS/UEFI (usually by pressing F2, F10, DEL, or ESC at boot).
  2. Look for Intel VT-x (for Intel CPUs) or AMD-V (for AMD CPUs).
  3. Enable the virtualization feature.
  4. Save and exit BIOS.
  5. Boot into Linux and check again using:
    egrep -c '(vmx|svm)' /proc/cpuinfo

3. Install and Enable KVM for Hardware Acceleration

If you're using an AMD Ryzen processor (which you are), you need KVM (Kernel-based Virtual Machine):

(A) Install KVM and Required Packages

sudo apt update sudo apt install -y qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager

(B) Check if KVM is Working

kvm-ok

If you see:

KVM acceleration can be used then your system is ready.

If KVM is not enabled, try:

sudo modprobe kvm_amd

and check again.


4. Use an ARM-based System Image Instead of x86_64

If your CPU does not support virtualization, you can use an ARM64 system image instead:

sdkmanager "system-images;android-34;google_apis;arm64-v8a" --sdk_root=/opt/android-sdk

Then create an emulator using the ARM64 image:

avdmanager create avd -n MyEmulator -k "system-images;android-34;google_apis;arm64-v8a"

And launch it:

emulator -avd MyEmulator -no-snapshot -noaudio -no-boot-anim

5. Run the Emulator with Software Rendering (Slow Alternative)

If you cannot enable virtualization, try running the emulator in software mode:

emulator -avd MyEmulator -no-accel -gpu swiftshader

This will be slow but allows the emulator to run.


6. Check Your File System (ext4 Warning)

You're also getting:

"File System is not ext4, disable QuickbootFileBacked feature"
This means your file system is not ext4 (e.g., Btrfs or XFS).
You can disable Quickboot by running:

emulator -avd MyEmulator -no-snapshot-load

Comments

Popular posts from this blog

Your build is currently configured to use incompatible Java 21.0.3 and Gradle 8.2.1. Cannot sync the project.

Google Assistant Implementation in Android application with app actions