android - javah doesn't find my class

Ask Questionjava

 

12linux

 

5android

I am having troubles generating the C header file for JNI using javah.es6

Here's the script I use while standing in the <project-dir>\bin directory:sql

javah -classpath C:\PROGRA~2\Android\android-sdk\platforms\android-8\android.jar com.test.JniTest

As return I get:app

ERROR: Could not find class file for 'com.test.JniTest'.

Even though the class JniTest certainly is in \com\test.ide

What am I doing wrong?post

android java-native-interface android-ndk javahthis

shareimprove this questiones5

edited Oct 3 '11 at 13:38

Joachim Sauer

242k5050 gold badges491491 silver badges567567 bronze badges

asked Oct 3 '11 at 13:26

KaiserJohaan

4,1001717 gold badges9090 silver badges174174 bronze badges

add a comment

 

3 Answers

activeoldestvotes

 

18

 

You specify the classpath to contain only android.jar.

You also need to include the location where your classes are stored. In your case it is the current directory, so you need to use . (separated by ; on Windows). The invocation should look like this:

javah -classpath C:\PROGRA~2\Android\android-sdk\platforms\android-8\android.jar;. com.test.JniTest

shareimprove this answer

answered Oct 3 '11 at 13:38

Joachim Sauer

242k5050 gold badges491491 silver badges567567 bronze badges

  • 1

    just adding, apparently you have to be outside the directory of the actual file. You can't just specify the name of the file. – L7ColWinters Mar 9 '12 at 17:45

  • Error: no classes specified errror cant get inside android.jar – Sunil Chaudhary May 23 '16 at 7:48

add a comment

 

18

 

If you are on Linux or MAC-OS, use ":" to separate the directories for classpath rather than ";"character: Example:

javah -cp /Users/Android/android-sdk/platforms/android-xy/android.jar:. com.test.JniTest

shareimprove this answer

edited Oct 9 '14 at 8:31

Hari Karam Singh

6,58055 gold badges3838 silver badges4747 bronze badges

answered Sep 21 '13 at 5:24

VJ Vélan Solutions

4,95744 gold badges4040 silver badges6262 bronze badges

  • 1

    that : in linux saved me :P – Sundeep1501 Oct 7 '15 at 10:31

add a comment

 

10

 

You should change the directory to <project-dir>\bin\classes; then, run the following command:

javah -classpath C:\PROGRA~2\Android\android-sdk\platforms\android-8\android.jar;. com.test.JniTest


I'm using the following command file to generate headers: jHdr.cmd on my desktop:

@echo on
SET PLATFORM=android-8
SET ANDROID_SDK_ROOT=C:\Android\android-sdk
SET PRJ_DIR=D:\Workspaces\sqLite\raSQLite
SET CLASS_PKG_PREFIX=ra.sqlite
cd %PRJ_DIR%\bin\classes
javah -classpath %ANDROID_SDK_ROOT%\platforms\%PLATFORM%\android.jar;.  %CLASS_PKG_PREFIX%.%~n1
pause


adjust variables to your needs ... 
put this file on your desktop, then drag you .java file from eclise to jHdr.cmd, result is under %PRJ_DIR%\bin\classes directory

相關文章
相關標籤/搜索