Build a Feathers UI project as an Android app
Feathers UI may be used to build mobile applications targeting Google's Android operating system.
In addition to the dependencies specified in the Feathers UI installation instructions, building an Android application with Feathers UI has some additional requirements.
Install the Java OpenJDK (version 8 or newer)
- Launch Android Studio at least once to go through its setup wizard that downloads the Android SDK components.
Note: The Android NDK is not the same as the Android SDK. You need both.
Do not download versions that are newer than NDK r21. NDK r22 and newer are not currently compatible with Haxe. The version of the NDK that Android Studio offers to install will be too new for Haxe.
Extract the archive somewhere on your file system, and take note of the absolute path because it will be used in a later step.
On macOS, be sure to download the Mac App Bundle rather than the .zip bundle. You will download a .dmg file. By using the signed and notarized Mac App Bundle, you will ensure that Gatekeeper does not block the executables from the NDK from running.
When you open the .dmg file, it will contain an .app file. Right click this .app file, and choose Show Package Contents. Inside the .app file, the NDK is located at Contents/NDK. Copy this folder somewhere on your hard drive.
Configure OpenFL for Android
To set the locations of various tools required to build Android apps, you need to run the following command:
openfl setup android
It will request the paths to several of the required tools that were installed in previous steps.
Pass in the absolute path of the Android SDK.
Run Android Studio at least one time to go through its setup wizard that downloads the Android SDK components.
Typically, when the Android SDK is installed by Android Studio, it is located at a standard location on each platform:
- Windows: C:\Users\username\AppData\Local\Android\Sdk
- macOS: ~/Library/Android/sdk
- Linux: ~/Android/Sdk
Pass in the absolute path where you extracted the Android NDK.
The Java JDK may be installed in a variety of locations, depending on which operating system you are using:
- Windows: Typically, Java is installed to C:\Program Files\Temurin or C:\Program Files\Java
- macOS: Run the /usr/libexec/java_home command in the Terminal app to find the JDK location.
- Linux: Run the whereis java command in a terminal to find the JDK location.
JAVA_HOMEshould be set to parent of the bin folder that contains the java executable.
To build for the
android target, run the following command.
openfl build android
-debug flag to create a build to include extra debugging information, including full stack traces when there's an exception or crash.
openfl build android -debug
The build's output will be written to the bin/android/bin folder. The .apk file may be found in bin/android/bin/app/build/outputs/apk/debug (including release builds).
Your project.xml file may optionally specify an output folder different from bin.
In the example above, the output would be generated in Export/android/bin instead.
Run / Debug
OpenFL provides the
test command to compile and launch your project executable on an Android device connected to your computer with USB.
openfl test android
Error on macOS says executables from the Android NDK "cannot be opened because the developer cannot be verified"
You may have downloaded the .zip version of the NDK, instead of the Mac App Bundle version of the NDK. The Mac App Bundle version of the NDK is signed and notarized, which means that macOS Gatekeeper trusts this version more, and you won't see these errors.
If, for some reason, you must use the .zip bundle, you can manually allow the executables through macOS Gatekeeper. However, be warned that it's a tedious process to get everything working correctly.
In the "developer cannot be verified" error dialog, click Cancel and stop the current build in your terminal.
Open the System Preferences app.
Choose Security & Privacy.
Go to the General tab.
In the Allow apps downloaded from: section, click the Allow Anyway button.
Start the build again.
This time the pop-up will ask if you are sure that you want to open the executable. Click Open.
You may need to repeat this process many times, so keep the System Preferences app open so that you can click the Allow Anyway button when it appears again. The same executable name may fail more than once. This is normal. Android supports many CPU architectures, and each has its own set of executables.
Error: arm-linux-androideabi-g++: command not found
There is more than one possible reason for seeing this error:
You may have downloaded the wrong version of the Android NDK. You must not use NDK versions newer than NDK r21 (and you probably shouldn't use versions older than r15c).
You may have used the wrong path to the Android NDK on your file system. Check that the root folder of the SDK contains multiple sub-folders and files, including a README file.
Error: Failed to install the following Android SDK packages as some licences have not been accepted.
You may need to install a specific version of the Android SDK platform tools in Android Studio. The error message will include the version that you need, in a format like this:
platforms;android-28 Android SDK Platform 28
Open the Android Studio settings, and install the Android SDK platform tools with the specified API version. For the example above, API version 28 refers to Android 9.0 (Pie).
Did you get some other error message that you don't understand?
Configuring OpenFL to build for native targets, like iOS or Android, can be a little tricky! Head over to either the Feathers UI community forum or the Feathers UI Discord. Explain which command you tried to run, be sure to mention that you are targeting android, and post the error message (and any additional relevant output). Ideally, we can help you figure out a solution, and then we'll also add it to this troubleshooting section, so that everyone can benefit.