(Using android sdk 25.1.6)
I am creating and opening Android emulator from the command line:
$> android create avd -n my_device -t 9 --skin 1440x2560 --abi default/x86
How can I set its pixel density?
I have tried the following approaches:
After running the above command I answer "yes" to creating a hardware profile. When I'm asked what density to use I type 570 but it does not accept it (it asks me the same question again) and only accepts empty input (default).
After creating the emulator, open ~/.android/avd/my_avd.ini and append:
hw.lcd.density=570
but this setting is ignored.
add this flag when opening the emulator:
$> emulator avd my_avd -dpi-device 570
but I get:
WARNING: The -dpi-device flag is obsolete and will be ignored
Any idea?
Here's a full solution that sets the pixel density as well as width and height. This matches the emulated device created through android studio/avd:
# Install AVD files
$ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-29;default;x86'
yes | $ANDROID_HOME/tools/bin/sdkmanager --licenses
# Create emulator
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n Pixel_API_29_AOSP -d pixel --package 'system-images;android-29;default;x86' --force
$ANDROID_HOME/emulator/emulator -list-avds
# Set screen dimensions
echo "hw.lcd.density=420" >> ~/.android/avd/Pixel_API_29_AOSP.avd/config.ini
echo "hw.lcd.height=1920" >> ~/.android/avd/Pixel_API_29_AOSP.avd/config.ini
echo "hw.lcd.width=1080" >> ~/.android/avd/Pixel_API_29_AOSP.avd/config.ini
echo "Starting emulator and waiting for boot to complete..."
nohup $ANDROID_HOME/emulator/emulator -avd Pixel_API_29_AOSP -no-snapshot -no-window -no-audio -no-boot-anim -camera-back none -camera-front none -qemu -m 2048 > /dev/null 2>&1 &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done; input keyevent 82'
echo "Emulator has finished booting"
$ANDROID_HOME/platform-tools/adb devices
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With