How to configure javah tool in Eclipse [duplicate]

2020-07-30 13:50发布

问题:

This question already has answers here:
Closed 6 years ago.

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

回答1:

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.



回答2:

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.

Hope this helps someone.



回答3:

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")