Tilt Five NDK  1.4.1
Getting Started : Android

Project Setup

The following files need to be included in your project

File(s) Purpose
.h (and possibly .hpp) files from the include directory C (and C++) header files for the API
Plus
android/TiltFiveAndroidClient.aar Combined AAR with the Tilt Five NDK support library
Or
android/TiltFiveAndroidClient.jar Android support for the Tilt Five NDK support library
lib/aarch64/libTiltFiveNative.so The Tilt Five NDK support library

How you include the files depends on how you're building Android applications.

A good place to start for instructions on how to include Android libraries in your application is the Android Developers User Guide.

Platform Context

On Android, t5CreateContext() or tiltfive::obtainClient() requires a platformContext parameter, which must be obtained from the Java (or Kotlin) part of your application. The below sample shows how to obtain the necessary context, which must be passed to your native code via JNI.

Kotlin code

package com.your.company
import androidx.appcompat.app.AppCompatActivity
import com.tiltfive.client.*;
class MainActivity : AppCompatActivity() {
lateinit var tiltFiveClient : TiltFiveClient
var platformContext : Long = 0
...
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
tiltFiveClient = TiltFiveClient(getApplicationContext())
platformContext = tiltFiveClient.newPlatformContext()
...
}
// Called from native via JNI
fun getPlatformContext(): Long {
return platformContext;
}
...
}

C code

long getPlatformContext(JNIEnv* jni, jobject obj) {
jclass clazz = jni->GetObjectClass(obj);
jmethodID methodId = jni->GetMethodID(clazz, "getPlatformContext", "()J");
return jni->CallLongMethod(obj, methodId);
}
...
long platformContext = getPlatformContext(jni, obj);
T5_Result err = t5CreateContext(&t5ctx, &clientInfo, platformContext);
...
uint32_t T5_Result
Represents an error code that may be returned by the Tilt Five™ API.
Definition: errors.h:47
T5_EXPORT T5_Result t5CreateContext(T5_Context *context, const T5_ClientInfo *clientInfo, void *platformContext)
Create a context object.

Next Steps

After you've included the necessary files in your build, and reserved the platform context, you can continue with either Getting Started : C or Getting Started : C++.