26
Jul
2017
11:25 AM

Quirks With Android Studio Emulator

Just installed Android Studio 2.3.3 on my debian box. Unfortunately, I can't get my emulator to start. If you have the same problem, this might be one of the ways to fix it.

This is instructions on how to get android studio 2.3.3 emulator to run with KVM. KVM is the default emulator to run android images on linux boxes. If you use windows, or mac, you probably have to follow some other instructions.

This instructions is specifically for debian Stretch and it might also work with jessie. I've managed to make mine work by referring to a few notable open source guide and good people willing to share their experiences. http://charlieraffellini.com/Enable-KVM-in-Debian/

For most, your experience would be simpler and less troublesome. But I ran into some quirks with my graphic card and it took a while to figure it out.

Requirements

One of the first things you should do is to see if you have hardware virtualization support for your processor. Run the command below in your terminal.

$ egrep -c '(vmx|svm)' /proc/cpuinfo
4

If you see a 0, that means your CPU does not support hardware virtualization. Mine says 4, for reasons im not really sure off, my guess is that this means that my processor can support 4 virtual cpus. If it says 0, well don't be discourage, there is a chance that Virtualization support is not enabled on your CPU. So what you can do is check for harware virtualization support in your bios. If you dont have that option, well tough luck, you might have to get a new machine.

If you have Virtualization support on your cpu, try running the command below.

$egrep '(vmx|svm)' /proc/cpuinfo

flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp

It should return something with a lot of lines, and it should show something containing "vmx" or "svm".

Next is to run the command

$ls -l /dev/kvm
crw-rw----+ 1 root kvm 10, 232 Jul 25 10:41 /dev/kvm

If you dont have that device block, you don't have kvm.

KVM installation

So how do you install KVM. Using apt-get to get the necessary files and also add your user account to the group kvm and libvirt.

$sudo apt-get install qemu-kvm libvirt-bin virtinst kvm virt-viewer
$sudo adduser <youruser> kvm
$sudo adduser <youruser> libvirt

After doing this, you might want to reboot your machine to have everything loaded.

Verify installation

To verify your installation, you can try running the following command and the output should show as below. If what you see is similar, you are good to go.

$ sudo virsh -c qemu:///system list

    Id Name                 State

    ----------------------------------

Graphic Card Quirks

For most cases, you can simply use your emulator now by creating a virtual device on android AVD (android virtual device) . Unfortunately, when i tried to run my virtual device, Android Studio seems to be idle and nothing seems to appear. I also tried to run a virtual device via the command line in hope to figure out what was wrong with it. And if you use command line, you will see why, it seems i have problems loading the correct drivers.

In the Android/Sdk/tools directory run the command below. You'll get a bunch of errors relating to your graphic display, you can try what I did to check the output. Apparently, due to having two graphic cards on my laptop, it has problems that I can't really explain. But it did mention about not being able to pick up my intel graphic driver.

$emulator -avd YOURDEVICE

MAke sure to use the exact same device name you use to create you virtual device on the AVD. Now if you do have a graphic card problem. The following steps might help.

First, locate lib64 folder.Since i am running debian. It's located under ~/Android/Sdk/emulator/lib64. In the terminal, Navigate to the ~/Android/Sdk/emulator/lib64 folder ,then run the following commands:

$ sudo apt-get install lib64stdc++6:i386
$ sudo apt-get install mesa-utils

then move the libstdc++.so.6 file inside the folder libstdc++.so.6.old

$ cd ~/Android/Sdk/emulator/lib64
$ mv libstdc++.so.6 libstdc++.so.6.old

then, get the system libstdc++ and link it, execute the command below

$ sudo ln -s /usr/lib32/libstdc++.so.6 libstdc++

You can now try to restart your Android Studio and run AVD to run your virtual device. If it works, yeay....

Conclusion

While this seems to work, I have no real way to say why it works. So at this point you should test if it works for you too. The performance is quite good. This also assumes you have sufficient memory and an i5 atleast to see it perform nicely. I have a i7 on my laptop.



You may also like