java JAVAH 找不到类(android ndk)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9985336/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JAVAH can't find class( android ndk)
提问by Alex Wih
I need a help in javah and android-ndk.
我需要 javah 和 android-ndk 方面的帮助。
I tryed to generate H-file for my native method, but javahsaid class file not found.
我试图为我的本机方法生成 H 文件,但javah说找不到类文件。
My target class has absolute name $PROJECT_DIRECTORY/src/bt/nativeclient/BtnativeActivity.javaand contains follow code:
我的目标类具有绝对名称 $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");
}
}
I tryed to start javahfrom follows pathes:
我尝试从以下路径启动javah:
$(PROJECT_DIRECTORY)/bin$ javah -jni bt.nativeclient.BtnativeActivity
$(PROJECT_DIRECTORY)/jni$ javah -jni bt.nativeclient.BtnativeActivity
$(PROJECT_DIRECTORY)$ javah -jni bt.nativeclient.BtnativeActivity
I tryed to specify -classpathpathes:
我尝试指定-classpath路径:
$PROJECT_DIRECTORY/src$ javah -classpath :. bt.nativeclient.BtnativeActivity
I tryed to specify android.jaras mentioned there:
我尝试指定那里提到的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.
Moreover, with -verboseoption command javahsays that this command was seaching my class it the valid place:
此外,使用-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.
I think I have lost some important thing, but I still can't find resolution.
我想我失去了一些重要的东西,但我仍然找不到解决办法。
Could anybody help me, please?
有人可以帮我吗?
回答by richq
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:
Android 构建系统的 ant 部分实际上将类文件放在bin/classes
. 所以你需要$PROJECT_DIRECTORY/bin/classes
在javah
类路径上有。例如,您可以从 src 目录运行:
$PROJECT_DIRECTORY/src$ javah -classpath ../bin/classes bt.nativeclient.BtnativeActivity
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.
这假设您首先将 Java 代码编译为相应的类文件。您可以通过查看 bin/classes 目录中的内容来检查 - 它应该包含bt
目录,这是您的包名称的顶部。
回答by Kari Pulli
In my case the problem was that the Windows Java was in the path before the Android java. So check (in cygwin) which javah you are using (which javah), and if the path doesn't look right, fix the path.
就我而言,问题是 Windows Java 在 Android java 之前的路径中。因此,请检查(在 cygwin 中)您使用的是哪个 javah(哪个 javah),如果路径看起来不正确,请修复路径。
回答by BALEPA
in my case I had to rename my package from 'com.examples.cam' to something else. Then javah worked properly. Before I had the same "class not found" error.
就我而言,我不得不将我的包从“com.examples.cam”重命名为其他名称。然后 javah 正常工作。在我遇到相同的“找不到类”错误之前。
回答by Amit Ahire
@richq is absolutely right. But there is one more thing that I would like to add. (And which has taken up most of my morning solving that)
@richq 是绝对正确的。但我还想补充一件事。(这占用了我早上的大部分时间来解决这个问题)
While specifying the classpath = Refrain from using ./bin/classes:~/ProjectFolder/bin/classes ( the tilde representing the Home directory)
在指定类路径时 = 避免使用 ./bin/classes:~/ProjectFolder/bin/classes ( the tilde representing the Home directory)
But use the "../../" to switch directories. For some reason javah doesn't recognizes the tilde operator for the home directory.
但是使用“../../”来切换目录。出于某种原因,javah 无法识别主目录的波浪号运算符。
Also one other thing if the class has a dependency on other project then you would need that as well in the classpath
还有一件事,如果该类依赖于其他项目,那么您在类路径中也需要它
user@laptop:~/SomeProject javah -classpath ./bin/classes:../<Whereever the path is>/SomeOtherDependentProject:../<Path to android-sdk>/android.jar <Qualified class path>
回答by suprith
Even I was stuck with this for a while and answer that richq worked like a charm. I would like to add that in classpath you should only provide the path till the start of your package (most projects its one level before com). For the next argument give class file path inside your packages (ie starting from com.mypackage.myclass) Also, do not append the class name with '.java' extention.
甚至我也坚持了一段时间,并回答说richq就像一种魅力。我想在类路径中补充一点,您应该只提供直到包开始的路径(大多数项目都在 com 之前的一个级别)。对于下一个参数,请提供包内的类文件路径(即从 com.mypackage.myclass 开始)此外,不要在类名后附加“.java”扩展名。
from 'src' of your package
来自您包裹的“src”
javah -classpath ../package1/package2/.. com.mypackage.myclassname
javah -classpath ../package1/package2/.. com.mypackage.myclassname