Javah Error android.app.Activity not found

大城市里の小女人 提交于 2019-12-17 16:27:38

问题


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


回答1:


Try adding to your classpath:

-classpath <android-sdk-location>/platforms/android-8.jar



回答2:


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



回答3:


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




回答4:


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




回答5:


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


来源:https://stackoverflow.com/questions/10483959/javah-error-android-app-activity-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!