To create Kanzi applications for Android you can use Android Studio, the Clang toolchain, and the Gradle build system.
Before you can deploy Kanzi applications to Android, set up your build environment. See Deploying Kanzi applications to Android.
To build and deploy Kanzi applications to Android devices using the Kanzi Android platform package, you need:
Kanzi supports Android API level 21 (Android version 5.0) and newer.
Kanzi does not support the JavaScript scripting functionality on Android.
This diagram shows the process that Kanzi uses to build an Android package.
The Android lifecycle events set how your Kanzi application behaves when the activity state changes. Each event maps to an Android activity callback method. A Kanzi application uses these lifecycle events:
Lifecycle.Event.ON_CREATE
// Load the native library that provides Kanzi functionality, // initialize the context, and assign the KanziView for rendering. // This function calls the KanziNativeLibrary.createApplication() function, // which loads the Kanzi project. KanziView.createNativeApplication();
Lifecycle.Event.ON_DESTROY
// Halt and destroy the Kanzi application.
// This function calls the KanziNativeLibrary.haltApplication() and
// KanziNativeLibrary.destroyApplication() functions.
KanziView.destroyNativeApplication();
SurfaceHolder.Callback.surfaceCreated
// When the application surface is created, run the Kanzi application.
KanziNativeLibrary.runApplication(holder.getSurface());
SurfaceHolder.Callback.surfaceDestroyed
// When the Kanzi application surface is destroyed, pause rendering.
KanziNativeLibrary.haltApplication();
SurfaceHolder.Callback.surfaceChanged
// When the format or size of the Kanzi application surface changes,
// resize the application surface.
// @param width: The new width of the surface.
// @param height: The new height of the surface.
KanziNativeLibrary.resizeEvent(width, height);
Kanzi does not use the LifeCycle.Event.ON_PAUSE
and Lifecycle.Event.ON_RESUME
events because they do not tell whether the application surface is ready for rendering. To pause and resume rendering, KanziView
uses the SurfaceHolder.Callback
surfaceCreated()
and surfaceDestroyed()
functions.
See https://developer.android.com/reference/androidx/lifecycle/Lifecycle.Event.html and https://developer.android.com/reference/android/view/SurfaceHolder.Callback.
This diagram shows the initialization sequence of a Kanzi application on the Android platform.
To run your Kanzi application in your Android application, you can add a KanziView to an existing Android Studio project.
To add a KanziView to an Android Studio project:
apply plugin: 'com.rightware.gradle.kanzi'
Configuration
and KanziView
classes.import android.content.res.Configuration;
import com.rightware.kanzi.KanziView;
MainActivity
class:public class MainActivity extends AppCompatActivity {
private KanziView mView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
mView = findViewById(R.id.kanzicontent);
mView.registerLifecycle(getLifecycle());
}
...
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
mView.setOrientation(newConfig.orientation);
}
}
buildscript { apply from: 'getkanzi.gradle' repositories { google() jcenter() flatDir { dirs getKanziPlugins().toString() } } dependencies { classpath 'com.android.tools.build:gradle:4.1.0' classpath 'com.rightware.gradle:kanzi:0.6.1' } ...
<com.rightware.kanzi.KanziView
android:id="@+id/kanzicontent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
apply plugin: 'com.android.application' apply plugin: 'com.rightware.gradle.kanzi' android { ... sourceSets { main { assets.srcDirs = [new File(rootDir, "bin")] } } } ... externalNativeBuild { cmake { path file("$projectDir/src/main/cpp/CMakeLists.txt") } } }