I'm trying to create a .h header file for a simple NDK project. Using cygwin I browse to myprojectDIR\jni directory, then execute this command:
javah -o com_myproject_MyActivity.h -classpath myprojectDIR\bin\classes com.myproject.MyActivity
then this error message appears:
Error: cannot access android.app.Activity
class file for android.app.Activity not found
I have a native method inside MyActivity class, so I tried to create a new class called NativeAccess (does not extend any class from the android SDK) and it worked fine, the .h file was created, ndk-build and test on device where successful!
So my problem is that I need my native methods inside android activities and services that I create, but I cant do that because the Javah command cannot access classes from inside the android-sdk itself. Please notice that I'm using (Windows-7 x64) and I have these environment variables:
ANDROID_NDK : C:\Android\android-ndk-r7b
ANDROID_SDK : C:\Android\android-sdk
ANT_HOME : C:\ANT\apache-ant-1.8.3
JAVA_HOME : C:\Program Files\Java\jdk1.7.0_02
PATH : %JAVA_HOME%\bin;%ANDROID_SDK%\tools;%ANDROID_SDK%\platform-tools;%ANDROID_NDK%;%ANT_HOME%\bin; (other unrelated stuff)
Thanks in advance
Try adding to your classpath:
-classpath <android-sdk-location>/platforms/android-8.jar
I found it, this is how it goes:
javah -o com_myproject_MyActivity.h -classpath <android-sdk-location>/platforms/android-8.jar;myprojectDIR\bin\classes com.myproject.MyActivity
Try the following in Eclipse,
Go to > Run | External Tools| External Tool Configurations
Under Program create new configuration by clicking small icon.
Name it.
Location would be : C:\Program Files\Java\jdk1.7.0_04\bin\javah.exe
Working Directory would be: ${workspace_loc:/My_First_NDK/bin/classes} and
Arguments would be: -classpath ${workspace_loc:/My_First_NDK/bin/classes} -bootclasspath "C:\adt-bundle-windows-x86-20140624\sdk\platforms\android-19\android.jar" -v -d ${workspace_loc:/My_First_NDK/jni} com.mypackage.ndk.HelloNDK
In order to generate native header files javah needs:
your classes (usually under build/intermediates/classes)
Android classes (usually under $ANDROID_HOME/platforms/android-%ver%/android.jar)
So you simply pass them in -classpath argument
The main challenge for me was basically passing both of them - you have to use : as a separator and paths must be absolute.
See Oracle docs
Thus you may end up with something like this: javah -classpath <full path to app>build/intermediates/classes/debug:<full path to sdk>/platforms/android-26/android.jar com.myproject.MyActivity
I found it, this is how it goes:
E:\workspeaceResearch\DAMMADARJNI\src>javah -classpath "E:\Software\sdk\platform
s\android-19/platforms/android-8.jar"; -jni com.dammadar.jni.Home_Screen
Related
I wanna use tesseract library with my application so i need to implement ndk.i download it add its path to my bash_profile.
export ANDROID_ADB=/Users/gokhanaliccii/Library/Android/sdk/platform-tools
export ANDROID_NDK=/android_ndk/android-ndk-r10d
export PATH=$PATH:$ANDROID_ADB:$ANDROID_NDK
My problem is appeared when i run -javah command at studio terminal. My command is
javah -d jni -classpath /Users/gokhanaliccii/Library/Android/sdk/platforms/android-19/android.jar:/Users/gokhanaliccii/Documents/gokhan_private/android_ocr/NDK_TEST/app/build/intermediates/classes/debug gokhanaliccii.kou.ndk_test.MainActivity
after i got this error i tried to add support libraries
I tried to solved it but i coulndt find solution i'm really exhausted i hope someone know how to solve it
My project is at /Users/gokhanaliccii/Documents/gokhan_private/android_ocr/NDK_TEST
Dont need cp for javah
Run javac on source that includes file with native headers.
Cd to path that is parent of the root of where the ".class" files are.
On cli or in terminal run the javah ( no cp needed )
If stuvk do the ndk samples and it will make sense . They walk u thru javah sample
After lot of researches and training i solved my problem.
javah -classpath /Users/gokhanaliccii/Library/Android/sdk/platforms/android-19/android.jar:/Users/gokhanaliccii/Library/Android/sdk/extras/android/support/v7/appcompat/libs/android-support-v4.jar:/Users/gokhanaliccii/Library/Android/sdk/extras/android/support/v7/appcompat/libs/android-support-v7-appcompat.jar:../../build/intermediates/classes/debug -d jni gokhanaliccii.kou.ndk_test.MainActivit
My result command is above.I tried it at android studio,classes files are at build/intermediadtes/classes/debug if you want try it at eclipse it is under bin folder.
I am using Ubuntu14.04, Eclipse Luna.
I am referring Hello World Example given link
http://www.ntu.edu.sg/home/ehchua/programming/android/Android_NDK.html
My project name is HelloNDK.
My project path is /home/androiddev/workspace_luna/HelloNDK
In AndroidManifest.xml
I can see package which I use is named as: com.delta.hellondk
Android.jar which automatically added in project which is under Android 5.0.1 & its location shown as
/home/androiddev/Applications/Android_sdk/sdk/platforms/android-21/android.jar
When I use javah command, I got error.
I use following line in terminal.
javah -jni -classpath /home/androiddev/workspace_luna/HelloNDK/bin/classes/;/home/androiddev/Applications/Android_sdk/sdk/platforms/android-21/android.jar -o HelloJNI.h com.delta.hellondk
&
javah -jni -classpath /home/androiddev/workspace_luna/HelloNDK/bin/classes/JNIActivity.class;/home/androiddev/Applications/Android_sdk/sdk/platforms/android-21/android.jar -o HelloJNI.h com.delta.hellondk
when I use following command, I got error as follows:
Error: No classes were specified on the command line. Try -help.
bash: /home/androiddev/Applications/Android_sdk/sdk/platforms/android-21/android.jar: cannot execute binary file: Exec format error
Now I search lots of keywords in google, stackoverflow regarding how to generate HelloJNI.h automatically.
But i failed.
Please guide me!
I know its repeate question should be get negative vote, should be 'On Hold'. But then also i doesn’t get any clue so i asked without hesitate.
When I'm trying to create a headerfile with javah I get an error that he can't find the Parcelable class.
Before I created the header with:
From %PROJECTDIR%/bin/classes/
javah -classpath com.my.project
But now I added the Parcelable to the native calls I include the android.jar to the commandline call:
From %PROJECTDIR%/bin/classes/
javah -classpath :~/shared/android.jar:~/shared/MyProject/bin/classes com.my.project
I will get this error:
Error: Class android.os.Parcelable could not be found.
What am I doing wrong?
I had the same error message but a different problem (under Windoze). For some reason i had to quote the classpath although there was no whitespace in the path:
C:\myProjectPath>javah -jni -classpath "C:\Users\myUserName\android-sdks\platforms\android-15\android.jar";bin\classes -d jni package1.package2.myInterestingClass
And this didn't work:
C:\myProjectPath>javah -jni -classpath C:\Users\myUserName\android-sdks\platforms\android-15\android.jar;bin\classes -d jni package1.package2.myInterestingClass
And it worked when using a relative path:
C:\myProjectPath>javah -jni -classpath ..\..\..\..\..\Users\myUserName\android-sdks\platforms\android-15\android.jar;bin\classes -d jni package1.package2.myInterestingClass
Spent a few hours on this, windows is really weird most of the time. Maybe this helps someone else.
Found the problem... I had one colon to many.
javah -classpath ~/shared/android.jar:. com.my.project
I have a kind of strange issue. In my bash script or Makefile, using aapt with absolute path does not work but if I am in the local directory it does.
If I do the following, it does not work:
aapt add $OUT/device.jar $OUT/classes.dex
The command does run and print this output:
'/homes/rsevile/CS307/bin/Device/classes.dex'...
But when trying to load the jar, the class that I am trying to load end up being not found.
The following does work though:
cd $OUT
aapt add device.jar classes.dex
Printing:
'classes.dex'...
This is the whole code being executed in the script (which works):
javac -d $(OUT)/classes -classpath ./layoutlib.jar src/com/device/client/*.java
jar cf $(OUT)/device.jar $(OUT)/classes $(OUT)/layoutlib
dx --dex --no-strict --output=$OUT/classes.dex $OUT/device.jar
cd $OUT
aapt add device.jar classes.dex
cd $ROOT
adb push $OUT/device.jar $ANDROID_OUT_DIR
I am confused why my class ends up being not found when using an absolute path with aapt.
Could anyone please explain to me why it is not working and how I could fix it to use a proper absolute path please?
Thank you.
I realized that aapt actually keeps the absolute path, there is no way around it.
I fixed the problem by reusing jar and using the -C option that lets me specify a directory.
I think I'm doing the classpath wrong on the command line, and I get the following error:
My android program uses Bitmap from the package android.graphics.Bitmap
thomas#THOMASDESKLINUX:~$ javah -verbose -classpath :/home/thomas/Documents/LinuxProgramming/AndroidSDKs/android-sdk-linux_x86/platforms/android-8.jar;/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/bin org.me.renderscene.Billboard
Error: No classes were specified on the command line. Try -help.
bash: /home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/bin: is a directory
and javah cant find the class
thanks!
The problem with your command is that you are using the Windows Path Separator ; on the command line, rather than the Linux Path Separator :. I also recommend to add the current directory to javah: ., the correct command to generate header in your case is:
javah .:/home/thomas/Documents/LinuxProgramming/AndroidSDKs/android-sdk-linux_x86/platforms/android-8.jar:/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/bin org.me.renderscene.Billboard
Tip: javah doesn't need all dependency libraries to generate the headers, it will output warnings but thats OK. So using this tip, we can generate the headers with:
javah .:/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/bin org.me.renderscene.Billboard