Building for Android x86

Application running in Android  emulator (x86)
Application running in Android  emulator (x86)
Application running in Android  virtual machine (x86_64)
Application running in Android  virtual machine (x86_64)

The usual Android CPU, used by most of physical Android devices, is Arm (32-bit or 64-bit). But sometimes it makes sense to build for Android x86 CPUs (32-bit x86, 64-bit x86_64). The main use is to run such applications in emulators and virtual machines, like emulators provided in Android SDK or a virtual machine installed using ISO from Android-x86 project.

To do this, build Android APK using our build tool like this:

castle-engine package --os=android --cpu=x86_64

You can add --fast and/or --mode=debug if you want.

Then just transfer the resulting APK inside the Android machine.

If you use an emulator installed by Android AVD Manager, and visible on the adb devices list, you can even install and run (showing logs from the device) using the standard install and run commands of our build tool, like this:

castle-engine --os=android --cpu=x86_64 install
castle-engine --os=android --cpu=x86_64 run

Note: Setting up the emulator using command-line AVD Manager was unexpectedly hard, due to an enormous amount of questions I had to answer about the emulated machine. I recommend to use GUI to create new emulators instead, run Android Studio and from More Actions choose AVD Manager.

Note: The behavior of command castle-engine package --target=android, which you can use to create an APK for a “normal” Android device, has not changed. It still builds only for Arm (32-bit and 64-bit, aka Aarch64), assuming these are systems used on actual devices. Though we’re open to change this some day (if usage of Android x86 rises, and will be useful for more than just “developers testing apps in virtual machines”).

This has already somewhat worked in the past, but now we made it better:

  1. Instructions to setup environment for this are adjusted on Android docs and Android FAQ. Following the stuff related to Android/x86 is completely optional, so if you have a working Android setup and are not interested in x86 support, just ignore it.

  2. Our support libraries are now packaged with x86/x86_64 variants too:

    The precompiled libraries are inside CGE services on Android. So you don’t need to do anything, just package for Android using the build tool commands shown above, and it will add the required libraries.

1 Like