Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javah Error android.app.Activity not found

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

like image 360
Ayesh Qumhieh Avatar asked May 07 '12 14:05

Ayesh Qumhieh


People also ask

Do I need to Install Java before installing Android Studio?

Before installing Android SDK, you need to install Java Development Kit (JDK). Read "How to install JDK". Ensure that your JDK is at or above 1.8. You can check your JDK version with command " javac -version " (compiler) and " java -version "(runtime).

Where is SDK Android Studio?

To open the SDK Manager from Android Studio, click Tools > SDK Manager or click SDK Manager in the toolbar. If you're not using Android Studio, you can download tools using the sdkmanager command-line tool.

How to download Android Studio Step by Step?

Install Android Studio on WindowsThe Welcome to Android Studio Setup dialog displays. Click Next to start the installation. Accept the default installation settings for all steps. Click Finish when the installation is done to launch Android Studio.


2 Answers

Try adding to your classpath:

-classpath <android-sdk-location>/platforms/android-8.jar
like image 88
JonnyBoy Avatar answered Oct 13 '22 22:10

JonnyBoy


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
like image 21
Ayesh Qumhieh Avatar answered Oct 14 '22 00:10

Ayesh Qumhieh