简体   繁体   English

Android NDK-在其他标头中包含c ++标头?

[英]Android NDK - Include a c++ header in a different header?

I have an Ability.h file that is dependent on an Effect.h file. 我有一个Ability.h文件,它是依赖于Effect.h文件。

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. 我需要使用javah生成头,但是我无法Ability.java类中定义效果依赖关系 ,我Ability.java从该依赖关系生成c ++头。

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. 此代码生成一个没有 foo()函数的* .h文件,好像无法识别它。 It does generate a proper file if I swap the return type to int and don't include the com_test_Effect. 如果我将返回类型交换为int且不包含com_test_Effect,它将生成适当的文件。

I do have both of the modules defined in the Android.mk file (com_test_Effect and com_test_Ability). 我确实在Android.mk文件中定义了两个模块(com_test_Effect和com_test_Ability)。

How to include an another c++ file directly in the Xyz.java class from which the *.h is generated by javah ? 如何直接包括另一C ++文件中的Xyz.java从中类*.hJAVAH产生?

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 ? 编辑:也可以这样询问问题:是否有一种方法可以传递C ++类型的参数或从作为C ++与Java之间接口的函数返回C ++类型的值? (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. (接口介质为JNI。)例如,您可以使用基本类型(例如int)进行转换,然后将其转换为jint等。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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