JAVAH 找不到类(android ndk) [英] JAVAH can't find class( android ndk)

查看:30
本文介绍了JAVAH 找不到类(android ndk)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要 javah 和 android-ndk 方面的帮助.

I need a help in javah and android-ndk.

我尝试为我的本地方法生成 H 文件,但 javah找不到类文件.

I tryed to generate H-file for my native method, but javah said class file not found.

我的目标类具有绝对名称 $PROJECT_DIRECTORY/src/bt/nativeclient/BtnativeActivity.java 并包含以下代码:

My target class has absolute name $PROJECT_DIRECTORY/src/bt/nativeclient/BtnativeActivity.java and contains follow code:

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:

I tryed to start javah from follows pathes:

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

但我总是只得到一个结果:

But always I get only one result:

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 表示该命令正在搜索我的类它的有效位置:

Moreover, with -verbose option command javah says that this command was seaching my class it the valid place:

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

我想我丢失了一些重要的东西,但我仍然找不到解决办法.

I think I have lost some important thing, but I still can't find resolution.

有人可以帮帮我吗?

推荐答案

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

The ant part of the Android build system actually places the class files in bin/classes. So you need to have $PROJECT_DIRECTORY/bin/classes on the javah classpath. For example, from the src directory you could run:

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

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

This assumes that you've compiled your Java code to the corresponding class files first. You can check by seeing what is in the bin/classes directory - it should contain the bt directory, which is the top of your package name.

这篇关于JAVAH 找不到类(android ndk)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆