Alex Wih Alex Wih - 4 months ago 32
Java Question

JAVAH can't find class( android ndk)

I need a help in javah and android-ndk.

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

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


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


I tryed to specify -classpath pathes:

$PROJECT_DIRECTORY/src$ javah -classpath :. bt.nativeclient.BtnativeActivity


I tryed to specify android.jar as mentioned there:

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

Could anybody help me, please?

Answer

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

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.

Comments