After my participation at the Intel Android CodeFest, I decided to make a tutorial on how to prepare Planet Conqueror to run on Intel based Android devices. The game uses the libGDX developer framework. I think it’s a good idea to write this article so that other developers using the same framework can successfully provide their apps with x86-architecture support and hopefully avoid any pitfalls while doing it.
My name is Antonio De Falco, and I am the creator of the game Planet Conqueror. Having graduated from University as a Game-Designer, I found myself inclined to develop games that are easy to get into but that still deliver long-lasting fun while playing it. I initially intended for it to be a pastime project. I viewed it as an experiment to see how a relatively complicated genre like RTS can be made approachable to the casual gamer while still keeping in balance with the appeal of a strategic game. However, Planet Conqueror grew to be an app worthy of introduction to a wider audience. Taking part in the CodeFest contest was an opportunity to do just that. I took great satisfaction in making it to the Top 5 and winning an advertising contract which helped to make a real difference.
Some time ago I was introduced to the CodeFest contest. While reading about it, I discovered that an app with x86 support was required to enter the contest. I immediately started to look into the benefits of having an app that is natively built to run on Intel powered Android devices. Quickly it was clear that apps could run much faster on devices by avoiding the bridge between ARM and x86. This interpretation layer converts native ARM builds to run on x86 architecture during runtime. This means there is a big chunk of processing power going to waste. Another benefit is that running an app on emulators with x86 system image instead of ARM would also speed up things. Therefore, it ensures that the time schedule for testing is held up and has a more fluent experience while avoiding miskicks or user errors. It was also important in the decision-making process to find out how many x86 devices there were out there. Sure, the amount of devices is relatively small but it is growing fast (https://software.intel.com/en-us/android/get-device). The next step was to find out how difficult it would be to implement the x86 nativity into a game running with the libGDX development framework. As it turns out, it’s easy. So, let me explain how to port your game to an x86 native game.
Planet Conqueror was built using libGDX version 0.9.8 (stable release) which did not have the needed support for Intel based devices. Luckily the newer version of the framework did. So first of all, we need to download the new version of libGDX (ver. 0.9.9 or higher). LibGDX offers stable releases that are tested and contain few to no bugs. Another option is to download the nightly builds that have more features but probably more bugs, too. If you want to risk it, you can download the nightly build otherwise go for the stable release. You’ll find both downloads here: http://libgdx.badlogicgames.com/download.html
Once the download is complete, extract the zip file to a location of your choice. We are going to overwrite some files and delete some others.
First copy "gdx.jar" from the extracted folder into the "libs" folder of core project.
Than we need to replace the "libgdx.so" files and the Android Backend in the Android project folder. Copy the "armeabi", "armeabi-v7a" and "x86" folders and "gdx-backend-android.jar" from the extracted folder into "...\YourApp-android\libs\" folder.
While you are in the libs folder of your Android project, go into "armeabi" and "armeabi-v7a" and delete the "libandroidgl20.so" files.
Lastly copy and paste "gdx-backend-lwjgl.jar", "gdx-backend-lwjgl-natives.jar" and "gdx-natives.jar" form your extracted folder into "...\YourApp-desktop\libs\" folder.
Having support for x86, ARM and ARMv7 incorporated in one "fat build" the Android OS will sort out what files to use all by itself. If you are using libGDX extensions for your app, you also need to copy the updated extension files to your project. In the case of Planet Conqueror it was the Freetype extension which allows loading font files instead of creating bitmap fonts.
Just like before, copy "armeabi", "armeabi-v7a" and "x86" folders from "libgdx \extensions\gdx-freetype\" to the "libs" folder of your Android project.
Do the same for "gdx-freetype.jar" and "gdx-freetype-natives.jar" in the core projects "libs" folder.
Now that the first step is complete, you can start your IDE. You may notice some code errors showing up. This is due to changes that were made to libGDX in between the two versions. Check the documentation and change log to solve the errors that are specific to your app.
After that, you are ready to compile a build with x86 support and start testing for functionality. To do that you need to set up the emulator with the x86 system image from Intel. You will find a detailed explanation on how to work with the x86 system image here: https://software.intel.com/en-us/android/articles/speeding-up-the-android-emulator-on-intel-architecture
I do recommend reading the article above because it contains a lot of extra information which I will skim or skip in this article. Since I am working with Windows, I will skip the procedure for other operating systems. So if you do not use Windows, please refer to the link above. To start your newly build APK on a x86 emulator you need a few perquisites. The Android SDK which you probably have already installed and a computer which runs on an Intel processor with support for "…Intel VT-x, EM64T and Execute Disable(XD) Bit functionality…". This all sounds more complicated than it actually is. I’ve managed to run an emulator with an x86 system image on an Intel Core 2 Duo E6600 first released around mid-2006. So, if you have a newer CPU, chances are that you got all of these perquisites. These functionalities must be enabled from the BIOS, but do not worry about it yet.
Let’s start by downloading the Intel HAXM (Hardware Accelerated Execution Manager) from here: https://software.intel.com/en-us/android/articles/intel-hardware-accelerated-execution-manager
Go to the location of the downloaded file and extract and/or execute "intelhaxm.exe" to start the install wizard. During installation progress you may get an error message, telling you that Intel VT-x is not enabled in the BIOS. If so, you need to abort the setup restart your computer and enter the BIOS at startup (Please refer to the Mainboard owner’s manual on how to enter the BIOS) there you need to set "Virtualization Technology" to "Enabled". Save and exit the BIOS and restart the installation of Intel HAXM following the same steps as before.
Now that we have the accelerator installed we need to create an AVD (Android Virtual Device) with an Intel system image. Choose an Android version you want to use and download the image here: https://software.intel.com/en-us/android/tools (find different versions on the bottom of the website). Or use the Android SDK Manager for convenience. Once you have your system image(s) start the AVD Manager from the Android SDK Tools "…\android-sdk\AVD Manager.exe" and create a new AVD. Set up the new AVD as you need it to be. The only thing you need to do differently is to set "CPU/ABI" to "Intel Atom (x86)" and you have an emulator that runs with x86 architecture.
All you have left to do is test your app according to your testing-checklist. Of course, you do not have to test everything if you already tested your app thoroughly. Confine your testing-checklist to things that are relevant for the CPU. Do a comparison of the two builds on the emulator and/or a device to see how much of a difference it makes with your app.
The process of implementing x86 support into Planet Conqueror was fairly easy thanks to the libGDX framework. It was just a matter of updating the development framework, copying some files into the project, and the build for x86 devices was ready. From here it was a matter of testing it out to see if there were any hiccups during runtime. Getting the x86 emulator running was the first step, and it was completed quickly because of the drivers available for Intel powered desktop machines. Getting a hold of an actual device with x86-architecture was a bit harder but also manageable. In the end, no hiccups were found, and a new version of Planet Conqueror was ready to be uploaded to the Store for the x86-community to download.
Based in Krefeld (Germany), Antonio De Falco is, among other things, an independent game developer for Android devices. He graduated from University, with a bachelor’s degree in game-design. Since his studies, he has worked in Cologne and Paris, where he gained further experience in the surroundings of experienced software development companies.
Other Related Articles and Resources