Reputation: 1015
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?
Upvotes: 13
Views: 15626
Reputation: 559
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.
from 'src' of your package
javah -classpath ../package1/package2/.. com.mypackage.myclassname
Upvotes: 0
Reputation: 313
@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)
While specifying the classpath = Refrain from using ./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.
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>
Upvotes: 1
Reputation: 1
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.
Upvotes: 0
Reputation: 21
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.
Upvotes: 2
Reputation: 56468
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.
Upvotes: 25