Terra Android Documentation

This was a project from Google Summer of Code 2017 implemented by Mauricio Pedro Vieira, you can find the pull request here

Pre-Requisites

In order to successfully compile and run Terra in your Android device you need to have installed in your computer:

Android SDK Tools This one can be downloaded here. You get the SDK tools by either downloading the android studio or just the command line SDK tools in the bottom of the page
Android NDK Tools Once you have downloaded the SDK Tools you can open the SDK manager that comes with it and install the NDK through there.
Java

Pre-Installation

In order for the compilation and deploy to work properly some changes are necessary in the CMakeLists.txt file under src/platforms/droid.

First, for the compilation to workout, it is needed to generate a standalone toolchain. It is important that this toolchain matches the architecture and target android version of the device you are aiming to. Inside the Android NDK folder installation, under build/tools there is a python script “make_standalone_toolchain.py”. You need to execute this script passing as parameter the architecture you are building to, the API you will be using and the folder in which you want to place the generated standalone toolchain. This is an example to build a toolchain for the ARM architecture with the 24 API and outputted in the standalone_toolchain_ARM folder under the Android NDK installation folder.

ou can find more details about how to customize your standalone toolchain here

Also, in this file, you need to update the directories on the top of it to be the ones in your machine.

ANDROID_HOME SDK Tools installation folder
BUILD_TOOLS Build Tools installation folder
ANDROID_NDK NDK installation folder
TOOLCHAIN Directory where your generated standalone toolchain was created
JAVA_HOME Java installation folder

It is also needed to adapt some commands to the specific architecture and API chosen. In the creation of the c++ shared libraries and the libnative_app_glue the option -march= should be adapted to have the architecture you are using.

In the generation of R.class, R.java and NativeActivity.unsigned.apk, android-24 need to be replaced by your target Android version.

Commands

To build terra application you can just go to the src directory and run make droid

To build and deploy terra application you go to the same directory and type make droid install

If you go inside the src/build directory you have access to the uninstall command by typing make uninstall

Important Files

Makefile General makefile to build terra
Makefile_droid Specific makefile to generate the main.c
RealMainP Contains the android_main function
VMCustom Customization module
androidEvents Main loop to check events from the Android platform
androidGraphics Android Graphics manipulation
AndroidManifest Regular Android Manifest from any app, mostly useful to grant permission for Terra to use the device hardware
CMakeLists.txt Compile the C code generated and standalone into an Android Native App