Files
filament/android/Windows.md
Romain Guy b3284edb36 Android standalone toolchains are not longer necessary (#874)
* Android standalone toolchains are not longer necessary

The latest NDK (19) contains ABI/API level specific command line
tools making standalone toolchains unnecessary. This change adapts
to the new model which greatly simplifies the build script and
ensures the latest version of the tools is being used.

Note that this requires a fairly recent version of CMake which fixes
a bug related to ranlib. This change was tested with CMake 3.13
(CMake 3.7 does not work).

* Modify CI build script to fetch recent CMake

* Remove dependency on standalone toolchains in Windows README

* Use correct CMake path

* Update NDK to latest

* Only download CMake and NDK for Android builds

* Add version constant for ninja

* Make output more quiet
2019-02-25 15:14:31 -08:00

3.4 KiB

Building Filament for Android on Windows

Prerequisites

In addition to the requirements for building Filament on Windows, you'll need the Android SDK and NDK. See Getting Started with the NDK for detailed installation instructions.

Ensure the %ANDROID_HOME% environment variable is set to your Android SDK installation location.

All of the following commands should be executed in a Visual Studio x64 Native Tools Command Prompt.

Desktop Tools

First, a few Filament tools need to be compiled for desktop.

  1. From Filament's root directory, create a desktop build directory and run CMake.
mkdir out\cmake-release
cd out\cmake-release
cmake ^
    -G Ninja ^
    -DCMAKE_CXX_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe" ^
    -DCMAKE_C_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe" ^
    -DCMAKE_LINKER:PATH="C:\Program Files\LLVM\bin\lld-link.exe" ^
    -DCMAKE_INSTALL_PREFIX=..\release\filament ^
    -DENABLE_JAVA=NO ^
    -DCMAKE_BUILD_TYPE=Release ^
    ..\..
  1. Build the required desktop host tools.
ninja matc resgen cmgen

The build should succeed and a ImportExecutables-Release.cmake file should automatically be created at Filament's root directory.

Build

  1. Create the build directories.
mkdir out\cmake-android-release-aarch64
mkdir out\cmake-android-release-arm7
mkdir out\cmake-android-release-x86_64
mkdir out\cmake-android-release-x86
  1. Run CMake for each architecture.
cd out\cmake-android-release-aarch64
cmake ^
    -G Ninja ^
    -DCMAKE_BUILD_TYPE=Release ^
    -DCMAKE_INSTALL_PREFIX=..\android-release\filament ^
    -DCMAKE_TOOLCHAIN_FILE=..\..\build\toolchain-aarch64-linux-android.cmake ^
    ..\..

cd out\cmake-android-release-arm7
cmake ^
    -G Ninja ^
    -DCMAKE_BUILD_TYPE=Release ^
    -DCMAKE_INSTALL_PREFIX=..\android-release\filament ^
    -DCMAKE_TOOLCHAIN_FILE=..\..\build\toolchain-arm7-linux-android.cmake ^
    ..\..

cd out\cmake-android-release-x86_64
cmake ^
    -G Ninja ^
    -DCMAKE_BUILD_TYPE=Release ^
    -DCMAKE_INSTALL_PREFIX=..\android-release\filament ^
    -DCMAKE_TOOLCHAIN_FILE=..\..\build\toolchain-x86_64-linux-android.cmake ^
    ..\..

cd out\cmake-android-release-x86
cmake ^
    -G Ninja ^
    -DCMAKE_BUILD_TYPE=Release ^
    -DCMAKE_INSTALL_PREFIX=..\android-release\filament ^
    -DCMAKE_TOOLCHAIN_FILE=..\..\build\toolchain-x86-linux-android.cmake ^
    ..\..
  1. Build.

Inside of each build directory, run:

ninja install

Generate AAR

The Gradle project used to generate the AAR is located at <filament>\android\filament-android.

cd android\filament-android
gradlew -Pfilament_dist_dir=..\..\out\android-release\filament assembleRelease
copy build\outputs\aar\filament-android-release.aar ..\..\out\

If you're only interested in building for a single ABI, you'll need to add an abiFilters override inside the build.gradle file underneath defaultConfig:

ndk {
    abiFilters 'arm64-v8a'
}

See NdkOptions for more information.

filament-android-release.aar should now be present at <filament>\out\filament-android-release.aar.

See Using Filament's AAR for usage instructions.