1

I found already about 5 answers, tried all of them and didn't get it working.

Env: Ubuntu 12.04/ Indigo

Run->External Tools->External Tools Configuration...

Created new Program Location: /usr/bin/javah /*$ which javah gives /usr/bin/javah */

Working directory: ${workspace_loc:/MyProject/bin/classes}

Attributes: -d ${workspace_loc:/MyProject/jni} com.myproject.MyActivity

Result of RUN: Could not find class file for 'com.myproject.MyActivity'

Run from terminal gives same result maxim@ubuntu:~/workspace/MyProject/bin/classes$ javah -jni com.myproject.MyActivity

Error: cannot access android.app.Activity class file for android.app.Activity not found maxim@ubuntu:~/workspace/MyProject/bin/classes$

SDK/NDK installed, external paths added. How to add missing parts? Thanks everybody.

Edited Jul 3

Moving native lib loading to a separate class solved the problem

Maxim
  • 4,152
  • 8
  • 50
  • 77
  • 2
    This question is not a duplicate of [Using javah on linux](https://stackoverflow.com/questions/11135720/using-javah-on-linux). Eclipse is another animal altogether. In addition, future visitors might be working on Windows or OS X. Its a disservice to point them to the wrong duplicate. – jww Aug 30 '14 at 12:20

3 Answers3

9

Elaborating on this post also mentioned in android developer's answer:

As you can see by the screen shot below, set up the external tools like this:

  1. In the Eclipse ADT, click on "Run", hover on the last option of the menu - "External Tools" and choose "External Tools Configurations"

  2. Set the paths up to the following:

    2.1. Location: wherever you installed Java C:\Program Files\Java\jdk1.7.0_13\bin\javah.exe

    2.2. Working Directory: your project's /bin/classes/ directory ${workspace_loc:/MyProject/bin/classes}

    2.3. Arguments: -jni ${java_type_name}

  3. Click on run (note that you have to have the java class selected)

  4. Using your file browser, check the /bin/classes/ directory - you should find the .h header file there.

enter image description here

Hope this helps someone.

Community
  • 1
  • 1
marienke
  • 2,465
  • 4
  • 34
  • 66
  • '${workspace_loc:/MyProject/bin/classes}' why we use $ here?can't we use absolute path? – dd619 Oct 31 '13 at 11:52
2

I had a very similar problem on linux too . it turned out that i didn't do it on the right folder.

Try to read it and see if it helps: Using javah on linux.

Community
  • 1
  • 1
android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • After all it says me: "Error: cannot access android.app.Activity class file for android.app.Activity not found" Any suggestion? – Maxim Jul 03 '12 at 16:53
  • have you put the correct path to your class ? android.app.Activity "belongs" to android : http://developer.android.com/reference/android/app/Activity.html so it's weird that you use the exact path as of google. what is your exact command ? – android developer Jul 03 '12 at 19:25
  • maxim@ubuntu:~/workspace/MyProject/bin/classes$ javah -jni com.myproject.MyActivity Error: cannot access android.app.Activity class file for android.app.Activity not found maxim@ubuntu:~/workspace/MyProject/bin/classes$ – Maxim Jul 03 '12 at 20:08
  • hmmm... never tried it on a class that extends Activity . maybe you need to add some extra parameters? try to create a different class that has very basic functions and run the javah on it. this will show if we are on the right direction. – android developer Jul 03 '12 at 20:41
  • I have a working example under Windows OS using cygwin, native lib is loaded in Activity class. Works fine, but I'll try. – Maxim Jul 03 '12 at 21:29
1

Based on Enke's answer I added more argument for convenience.
1.You don't have to set working dir correctly by using "-classpath ".(You can ignore the working dir setting in the pic.)
2.You can get verbose info from integrated console in Eclipse.
3.You can specify output dir by using "-d " parameter.
*Don't forget to replace the project directory name in this pic.("MyProject")

How to set JavaH execution parameter in Eclipse project.

SONIC3D
  • 489
  • 4
  • 6