1. Are you ready for the Galaxy S20? Here is everything we know so far!

Can a fully native Android app call custom Java?

Discussion in 'Android Development' started by Marius Myburg, Jan 10, 2019.

  1. Marius Myburg

    Marius Myburg Lurker
    Thread Starter

    Good day.

    It is possible to change for example the native-plasma example, which is a fully native Android app with only C++ and no Java or Kotlin, to be able to call custom Java/Kotlin that you add to the app?

    I have used native-plasma as a base for an application, and now I need to call into third-party libraries, which they provided as Java, of course. But I cannot seem to find a way to now import their libraries and use their classes.

    I tried the following:

    1) Get ANativeActivity* activity from android_app*.
    2) Get JavaVM* vm from this.
    3) Call AttachCurrentThread on this vm to get a new JNIEnv*.

    But now calling FindClass on this JNIEnv* always returns NULL. I have not tried to get things like Java/Lang/String, I am quite sure that will work, but I am trying to get to a class that I added to my project myself.

    Would anyone be so kind to please get the ready-made native-activity example from the NDK samples and just try to somehow invoke a Java or Kotlin method from the native code? I will really appreciate a solution or a definite answer that it is not possible if it is not.

    Thank you!


Share This Page