简体   繁体   中英

Android NDK - Include a c++ header in a different header?

I have an Ability.h file that is dependent on an Effect.h file.

I need to use javah to generate my header, but I'm unable to define an Effect dependency in my Ability.java class from which I'd 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 an *.h file without the foo() function, as if it couldn't recognize it. It does generate a proper file if I swap the return type to int and don't include the com_test_Effect.

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

How to include an another c++ file directly in the Xyz.java class from which the *.h is generated by javah ?

Edit: The question can also be asked like this: Is there a way to pass C++-type arguments or return a C++-type value from a function that is an interface between C++ and Java ? (The interfacing medium being JNI.) For example, you can do so with basic types like int which then gets converted to jint and so on.

What 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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM