Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a header file for android activity class

I have added few native methods to my android Activity class.Now I want to create the header file for that class.

I get the following error while creating the header file from command line.

C:\AndroidProjects\JniTest\bin\classes>javah -classpath .;
C:\adt-bundle-windows-x86\sdk\platforms\android.jar com.example.jnitest.JniTest
Error: cannot access android.app.Activity
class file for android.app.Activity not found

Basically unable to access the activity class form the jar.

Please advice.

like image 747
amj Avatar asked Mar 13 '13 05:03

amj


Video Answer


2 Answers

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

enter image description here

like image 91
Punith K Avatar answered Sep 30 '22 08:09

Punith K


The command would be (use backslashes (\), instead of forward slashes (/) while using Windows cmd):

javah -bootclasspath $ANDROID_SDK_ROOT/platforms/android-17/android.jar -classpath bin/classes com.example.jnitest.JniTest

You should use -bootclasspath instead of -classpath, since android.jar re-implements Java Class Library.

Assumptions:

  • Your current directory is: C:\AndroidProjects\JniTest;
  • Your Android SDK is installed in $ANDROID_SDK_ROOT (%ANDROID_SDK_ROOT% for Windows);
  • Your target API Level is android-17.

Please modify your command accordingly.

like image 30
Siu Ching Pong -Asuka Kenji- Avatar answered Sep 30 '22 10:09

Siu Ching Pong -Asuka Kenji-