Run Android App in Qemu-Arm

How does native android code written for ARM run on x86?

Yes, ARM native code runs on Intel x86 using an emulation feature named Houdini

What this library does is reads ARM instructions on the fly and converts them to equivalent x86 instructions. This is the reason why many apps may work as is on x86 without actually having to build an equivalent library.

Sample Image

Does Android x86 emulate ARM?

First thing first, Android apps (pure Java) are not actually being "compiled for ARM, just like Java apps are compiled into a intermediate Java bytecodes to to executed by any platforms that supports JVM, Android apps written in Java are compiled into Dalvik bytecodes to be run on any platform that supports Dalvik VM. In this regard, how Android apps run x86 or ARM or MIPS is similar to how Java apps run on x86, SPARC, POWER, etc.

Of course if an app contains native code, then the app would need to include support for x86 to be run on an x86 emulator or an actual x86 phone/tablet.

As for the second part of your question, remember that the OS part of Android has been compiled to the x86 platform, so I would assume running x86 Android on a x86 computer is exactly same as running, for example, a Windows in a VM when using OSX.

ARM NEON support in Qemu

These values are stored in elf_hwcap (see kernel/setup.c). The vfp/vfpmodule.c detects NEON support and sets a bit in elf_hwcap. Specifically via this code,

            /*
* Check for the presence of the Advanced SIMD
* load/store instructions, integer and single
* precision floating point operations. Only check
* for NEON if the hardware has the MVFR registers.
*/
if ((read_cpuid_id() & 0x000f0000) == 0x000f0000) {
#ifdef CONFIG_NEON
if ((fmrx(MVFR1) & 0x000fff00) == 0x00011100)
elf_hwcap |= HWCAP_NEON;
#endif
#ifdef CONFIG_VFPv3
if ((fmrx(MVFR1) & 0xf0000000) == 0x10000000)
elf_hwcap |= HWCAP_VFPv4;
#endif
}

The read_cpuid_id() is a macro for the co-processor CP15 which gets a cpu id bit map. The fmrx() also uses another VFP co-processor register. So the emulator you are using is not responding properly to MRC instructions from either co-processor register; or maybe it does not support NEON emulation.

Android emulator is based on QEMU. Can I use KVM with it?

Yes, you can. Just download the appropriate Intel atom CPU packages in the Android SDK and have your AVD use an Intel atom CPU architecture. The android emulator can even use the host gpu. Here is a link on how to do it:

http://developer.android.com/tools/devices/emulator.html#acceleration

Android Studio/Emulator on macOS with ARM CPU M1

Good news !

Edit on 28 th of July 2021 /p>

Apple Silicon Support

Now, there is an arm64 release version available for Android Studio Arctic Fox (2020.3.1)
You can download it from here https://developer.android.com/studio#downloads

Easy fix to use right architecture

Tools -> SDK Manager -> SDK Tools (tab) -> Deselect 'Android Emulator' -> OK

Now, when you try to run your app, or launch device from AVD Manager, it will give the 'Install Emulator' error -> Click Ok. This will automatically download the correct version.

Use an arm64-v8a image !

  • Tools -> SDK Manager
  • Install Android 11 (R) or 12.0 (S) and click Apply
  • Tools -> AVD Manager -> click Create Virtual Device
  • Choose any device that has the Google Play Store icon and click Next
  • Choose an arm64-v8a on "Other Images" tab

Android studio

  • When NDK runs into Unknown host CPU architecture: arm64 you can solve it here

  • kapt doesn't work Solved https://stackoverflow.com/a/68285501/1079990



Related Topics



Leave a reply



Submit