4

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.

ScarletAmaranth
  • 5,065
  • 2
  • 23
  • 34
  • "don't include the com_test_Effect". That part of it has no effect. You aren't 'including' anything here, you are loading libraries at runtime. It has no magical effect on the Java compiler or `javah`. I would ask have you compiled the `Effect` class? – user207421 May 13 '12 at 12:31
  • @EJP Yes, the Effect is compiled, but just because it doesn't depend on anything. I wonder how to use c++ types in Xyz.java so that javah can then generate a proper *.h file. – ScarletAmaranth May 13 '12 at 12:34
  • @EJP Suppose i don't want to use "Effect" there but std::string. Given that stl is enabled, i still can't include the header. Well, i can do it in the *.cpp file but not in the c++ header. – ScarletAmaranth May 13 '12 at 12:41
  • 3
    You can return or pass to JNI function only the Java types (jint, jstring, jobject, ... etc). Not a C types (pointers/structs), and not a C++ types (std::strings). Can you show us your header files? – Mārtiņš Možeiko May 13 '12 at 19:13

1 Answers1

-1

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);
}
JonnyBoy
  • 1,555
  • 14
  • 24