我需要javah和android-ndk的帮助。
我试图为 native 方法生成H文件,但是 javah 说找不到的类文件。
我的目标类的绝对名称为$ PROJECT_DIRECTORY/ src/bt/nativeclient/BtnativeActivity.java ,并包含以下代码:

package bt.nativeclient;

import android.app.Activity; import android.os.Bundle; import android.widget.TextView;

public class BtnativeActivity extends Activity  {
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        TextView  tv = new TextView(this);
        tv.setText( stringFromJNI() );
        setContentView(tv);
    }

    public native String stringFromJNI();

    static
    {
        System.loadLibrary("hello-jni");
    }
 }
我尝试从以下路径启动 javah :
$(PROJECT_DIRECTORY)/bin$ javah -jni bt.nativeclient.BtnativeActivity
$(PROJECT_DIRECTORY)/jni$ javah -jni bt.nativeclient.BtnativeActivity
$(PROJECT_DIRECTORY)$ javah -jni bt.nativeclient.BtnativeActivity
我尝试指定 -classpath 路径:
$PROJECT_DIRECTORY/src$ javah -classpath :. bt.nativeclient.BtnativeActivity
我尝试指定there来指定 android.jar :
$PROJECT_DIRECTORY/bin$ javah -classpath :/home/l/android-sdks/platforms/android-10/android.jar:. bt.nativeclient.BtnativeActivity
但是我总是只能得到一个结果:
error: cannot access bt.nativeclient.BtnativeActivity
class file for bt.nativeclient.BtnativeActivity not found
javadoc: error - Class bt.nativeclient.BtnativeActivity not found.
Error: No classes were specified on the command line.  Try -help.
此外,使用 -verbose 选项命令 javah 表示此命令将我的类(class)隐藏在有效位置:
$PROJECT_DIRECTORY/src$ javah **-verbose** -classpath :/home/l/android-sdks/platforms/android-10/android.jar:. bt.nativeclient.BtnativeActivity
error: cannot access bt.nativeclient.BtnativeActivity
class file for bt.nativeclient.BtnativeActivity not found
javadoc: error - Class bt.nativeclient.BtnativeActivity not found.
[ Search Path: /usr/lib/jvm/java-6-openjdk/jre/lib/resources.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/rt.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/jsse.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/jce.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/charsets.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/netx.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/plugin.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/rhino.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/modules/jdk.boot.jar:/usr/lib/jvm/java-6-openjdk/jre/classes/:/home/l/android-sdks/platforms/android-10/android.jar:. ]
Error: No classes were specified on the command line.  Try -help.
我想我已经失去了一些重要的东西,但是我仍然找不到解决方法。
有人可以帮我吗?

最佳答案

实际上,Android构建系统的ant部分将类文件放置在bin/classes中。因此,您需要在$PROJECT_DIRECTORY/bin/classes类路径上具有javah。例如,可以从src目录运行:

$PROJECT_DIRECTORY/src$ javah -classpath ../bin/classes bt.nativeclient.BtnativeActivity

假设您已先将Java代码编译到相应的类文件中。您可以通过查看bin/classes目录中的内容进行检查-它应该包含bt目录,该目录位于软件包名称的顶部。

10-06 08:49