Android NDK - include C ++ header in another header?

I have an Ability.h file, which depends on the Effect.h file.

I need to use javah to create my header, but I cannot determine the effect dependency in my Ability.java class from which I would like the C ++ header to be generated.

Example:

 public class Ability { static { System.loadLibrary("com_test_Effect"); System.loadLibrary("com_test_Ability"); } public native Effect foo(Effect x); } 

This code generates a * .h file without the foo() function, as if it could not recognize it. It generates the correct file if I change the return type to int and do not include com_test_Effect.

I have both modules defined in the Android.mk file (com_test_Effect and com_test_Ability).

How to include another C ++ file directly in the Xyz.java class from which *.h javah is created?

Edit: the question can also be asked this way: is there a way to pass arguments of type C ++ or return a value of type C ++ from a function that is the interface between C ++ and Java? (The communication interface is JNI.) For example, you can do this using basic types such as int, which are then converted to jint, etc.

+4
source share
1 answer

How about returning an object:

 private native Object fooNative(Object x); 

Then convert it so that it has the same signature:

 public Effect foo(Effect x) { return (Effect)fooNative(x); } 
-1
source

Source: https://habr.com/ru/post/1412246/


All Articles