HardCoder
HardCoder

Reputation: 3036

How to call Java from NDK C++?

I need to call various Java functions while in native C++ to do some stuff (loading gfx, etc...) and would like to know how. Does anyone of you know some samples or have a few helpful code snippets ?

Upvotes: 1

Views: 2226

Answers (1)

npal
npal

Reputation: 539

To call Java functions from NDK you have to use JNI.

A useful and simple example is provided at the following link:

Invoke Java from C/C++

But I suggest that you should:

  • Not create a new Java Virtual Machine as in the above example. Instead you should use the JavaVM* and JNIEnv* that you get when you call the NDK functions.
  • Be careful for memory leaks when you use NDK.

Upvotes: 2

Related Questions