JAVAH 找不到类( android ndk)

2022-09-04 07:16:55

我需要javah和android-ndk的帮助。

我试图为我的本机方法生成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

我试图指定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说这个命令正在搜索我的类,它是有效的地方:

$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.

我想我失去了一些重要的东西,但我仍然找不到解决方案。

任何人都可以帮我吗?


答案 1

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

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

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


答案 2

就我而言,问题在于Windows Java处于Android Java之前的路径中。因此,请检查(在cygwin中)您正在使用哪个javah(哪个javah),如果路径看起来不正确,请修复路径。


推荐