androidjvmjava-native-interfaceclasspath

Is it possible to create Android activity from JNI?


My app is C++, it creates a JNI JVM (raw JVM, with class path to some of my .class files).

The JVM above is rather a core Java Virtual Machine without knowing about android.

How to add class path to Android SDK to do something like:

import android.content.Intent;

in my .java files?

Those imports are to use some of classes eg. android.content.Intent, etc. to create some activities.

With just C++, JNI JVM, Android SDK, and no Android Studio, is it possible to create MainActivity for the app?

Edit:

I found the way to add android.jar in the SDK to class path, but a new problem is android.content.Context is abstract and can't be instantiated to use the method .startActivity in it.


Solution

  • If you want your application to be native-first, you can use a GameActivity (or the more older NativeActivity) for your main activity.

    If you want to add screens with native UI controls, the easiest way forward is to add a Java/Kotlin activity and start it from your native activity with JNI. You can pass results back and forth by embedding it in the Intent you use to start it, or receive back from onActivityResult, or simply by setting some shared variables.