Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Mobile / Android

Haxe Toolkit: Compilation for Intel® x86 for the Android Platform

0.00/5 (No votes)
1 Feb 2016CPOL5 min read 10K  
This document describes the step-by-step instructions for building a Haxe* project (OpenFL*) for Intel® x86 for the Android* platform.

This article is for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers

Intel® Developer Zone offers tools and how-to information for cross-platform app development, platform and technology information, code samples, and peer expertise to help developers innovate and succeed. Join our communities for Android, Internet of Things, Intel® RealSense™ Technology, and Windows to download tools, access dev kits, share ideas with like-minded developers, and participate in hackathon’s, contests, roadshows, and local events.

This document describes the step-by-step instructions for building a Haxe* project (OpenFL*) for Intel® x86 for the Android* platform.

Haxe is an open source programming language. While most other languages are bound to their own platform (Java* to the JVM, C# to .NET, ActionScript to the Flash* Player), Haxe is a multiplatform language.

You can use Haxe to target the following platforms:

  • JavaScript*. You can compile a Haxe program to a single .js file. You can access the typed browser DOM APIs with auto completion support and all the dependencies are resolved at compilation time.
  • Flash. You can compile a Haxe program to a .swf file. Haxe is compatible with Flash Player 6 to 11. Haxe offers good performance and language features to develop Flash content.
  • NekoVM*. You can compile a Haxe program to NekoVM bytecode. This can be used for server-side programming, such as dynamic webpages (using mod_neko for Apache), and also for command-line or desktop applications, since NekoVM can be embedded and extended with some other DLL.
  • PHP. You can compile a Haxe program to .php files. This enables you to use a high-level strictly typed language such as Haxe while keeping full compatibility with your existing server platform and libraries.
  • C++. You can generate C++ code from your Haxe source code, with the required Makefiles, a useful capability for creating native applications. The NME library uses this to run Haxe code on iOS*, the Android* platform, and so on. As of 2.10 it also includes debugging.
  • C# and Java. You can generate source code for these targets as of Haxe 3.0.

The idea behind Haxe is to let the developer choose the best platform for a given job.

Setup and Prerequisites

Before starting, you’ll need to download and install the following:

  1. Download the Android SDK
  2. Download NDK.
  3. Download and install Cygwin*: When asked to select packages, search for the following packages and install them:
    1. Autoconf, Automake, binutils, gcc-core, gcc-g++, gcc4-core, gcc4-g++, gdb, pcre, pcre-devel
    2. gawk, make, python

    Note: Select the GUI version of make as well; otherwise, you will not be able to build your project using NDK.

  4. Download the Java Development Kit (JDK).
  5. Download Apache Ant*.

Next, edit the environmental variables.

  1. Set JAVA_HOME = the path in which you have installed the Java JDK. For example:

    C:\Program Files\Java\jdk1.7.0_45

  2. Set ANDROID_SDK_ROOT = the complete path to the SDK folder. For example: Download and extract the ADT bundle in

    D:\android\, so my path is: D:\android\adt-bundle-windows-x86-20131030\sdk

  3. Set NDK_ROOT = the complete path to the NDK folder. For example:

    D:\android\android-ndk-r9b

  4. Set NDK_ROOT = the complete path to the NDK folder. For example:

    D:\android\android-ndk-r9b

  5. Update the Path variable to contain the following = path to the JDK folder, JDK bin folder, NDK, Cygwin bin folder, ANT bin folder, SDK tools folder, and SDK platform-tools folder, each separated by a semi-colon (;). For example:

    D:\cygwin64\bin;C:\Program Files\Java\jdk1.7.0_40\bin;D:\android\adt-bundle-windows-x86_64-20131030\sdk\tools;D:\android\adt-bundle-windows-x86_64-20131030\sdk\platform-tools;%JAVA_HOME%\bin;%ANT_HOME%\bin

NOTE: Do not end any variable with "\" , “`", or any such special character.

Getting the HAXE and Corresponding Libraries

You can get the Haxe from sources using the instructions at https://github.com/HaxeFoundation/haxe or download the prebuilt source from http://haxe.org/download.

Here are the steps for downloading HAXE and corresponding libraries:

  1. Download HAXE from prebuilt sources from http://haxe.org/download. Choose the windows installer.
  2. Double-click the installer after download, and then follow the installation steps.
  3. The installer sets the environment variable HAXEPATH and appends to the system PATH environment variable. If not, please do what’s necessary. For example: Create a env HAXEPATH to the installed path such as E:\HaxeToolkit\haxe\ and then add the path to the system PATH env.
  4. The automatic installer will install NekoVM, which is used for some Haxe tools such as haxelib and haxedoc. If you are building from sources, please download and install neko from http://nekovm.org/download.

    Note: set NEKO_INSTPATH to the Neko. For example, E:\neko-2.0.0-win\ and add NEKO path to system PATH env.

  5. Install the required libraries that are part of OpenFL using the following:

    Note: haxelib is part of haxe and resides in the HAXEPATH.

    1. haxelib install openfl
    2. haxelib install hxcpp
    3. haxelib install hxlibc
    4. haxelib install openfl setup android

    Note: You can install through haxelib, or you can skip this step by giving local installation directories for Android SDK, NDK, and Ant, as shown in the following screenshot.

    Image 1

  6. Now that the libraries are installed, you can build the procedure. You can check the installed libraries by typing the following commands:
    1. >haxe
    2. >haxelib
    3. >openfl
    4. >neko

    For example, your screen will look like the following when you type haxe:

    Image 2

Build Procedure

Creating a Sample Application (OpenFL)

A sample OpenFL application can be created using the following command:

>haxelib run openfl create DisplayingABitmap

The above command creates a sample project.

Building the Application for x86 for Android

The following command should be used for building/cleaning the haxe OpenFL application for x86 for Android:

>haxelib run openfl build android –DHXCPP_X86 –verbose
>haxelib run openfl clean android –DHXCPP_X86 –verbose

Configuring Haxe OpenFL for x86 for Android

The following files can bring in or add the x86 configuration settings for Android:

  • haxe/lib/hxlibc/1,0,0/build-tool/gcc-toolchain.xml
  • haxe/lib/hxlibc/1,0,0/build-tool/android-toolchain.xml
  • haxe/lib/hxtools/1,1,3/src/platforms/AndroidPlatform.hx
  • haxe/lib/hxtools/1,1,3/project/HXProject.hx
  • openfl-native/1,1,1/project/Build.xml to get -x86 suffix

Output or Binaries

The final binary generates to

<projectDir>/Export/android/obj/libApplicationMain.so

The libraries generate to

<projectDir>\Export\android\bin\libs\x86

Known Issues or Additional Info

  • Installation of a package fails. For example: haxelib install openfl fails saying
    • "Error Connect/Blocking"
    • Solution: Make sure the proxy settings are set if you are using a proxy for the Internet; for example: haxelib proxy
  • openfl build android fails saying:
    • ANT/...build.xml , target 16/XX not found
    • Solution: Add the following in the project.xml for the OpenFL project: <android target-sdk-version="19" /> // where 19 is one of the available SDKs.

Resources

http://haxe.org/

https://github.com/HaxeFoundation/haxe

About the Author

Praveen Kundurthy works in the Intel® Software and Services Group. He has a master’s degree in Computer Engineering. His main interests are mobile technologies, Microsoft Windows*, and game development.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)