Android NDK: Eclipse parameter and javah

僤鯓⒐⒋嵵緔 提交于 2019-12-22 13:59:27

问题


I spent hours and hours on it not moving an inch forward. I have redone the project several times and nothing else is left outside places. Hope someone here can shed some light pointing out some direction.

On Linux Eclipse IDE panel > Run > External Tools > External Tools Configurations:

Name: Dev javah
Tab [main]:
* location: /usr/java/jdk1.6.0_25/bin/javah
* working directory: ${workspace_loc:/Dev/bin}
* Arguments: ??

I have tried:

* Arguments: -d ${workspace_loc:/Dev/jni} com.dev.DevActivity ${project_classpath:Dev} com.pkgpub.DevActivity

which gives me:

1 error
javadoc: error - Illegal package name: "/home/user/dev/Dev/bin/classes"

and also tried:

* Arguments: -d ${workspace_loc:/Dev/jni} com.dev.DevActivity

That gives...

error: cannot access com.dev.DevActivity
class file for com.dev.DevActivity not found
javadoc: error - Class com.dev.DevActivity not found.
Error: No classes were specified on the command line.  Try -help.

similarly to -

* Arguments: -d ${workspace_loc:/Dev/jni} com.pkgpub.DevActivity

That gives me:

error: cannot access com.pkgpub.DevActivity
class file for com.pkgpub.DevActivity not found
javadoc: error - Class com.pkgpub.DevActivity not found.
Error: No classes were specified on the command line.  Try -help.

But when I run:

which javah
/usr/bin/which: no javah in (/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/user/android-sdks/tools:/home/user/android-sdks/platform-tools:/opt/android/android-ndk-r7:/home/user/.local/bin:/home/user/bin:/home/user/android-sdks/tools:/home/user/android-sdks/platform-tools:/opt/android/android-ndk-r7:/home/user/android-sdks/tools:/home/user/android-sdks/platform-tools:/opt/android/android-ndk-r7)

The question is... the project is not compiling because javah is not visible to Eclipse NDK, or due to parameter details that something is missing? And in such case, how to get it fixed?

Thanks.


回答1:


try adding

-classpath bin/classes

as parameter to javah




回答2:


Specially for Android:

use classes right after bin like project_location/bin/classes, this worked for me on Linux Fedora

javah -d /var/www/project/jni/ -classpath /var/www/project/bin/classes/ com.android.TestClass



回答3:


@BlackBelt - thanks man for your suggestion!

Here is the parameter that worked, solving the javah side for the compiling process:

-d ${workspace_loc:/Dev/jni} com.pkgpub.Dev -classpath ${workspace_loc:/Dev/bin/classes/} com.pkgpub.Dev

Where pkgpub is the package name, and Dev is the project name. It is worth to mention that the project has the files: \src\Dev.java; \jni\Dev.c; \jni\Dev.h; \bin...\pkgpub\Dev.class.

Now it generates the file jni/com_pkgpub_Dev.h with the right content. Which is great!

However the ndk-build is still not completely linking, and does not generate the com_pkgpub_Dev.c file. So, from Project > Project Build - comes the message:

**** Build of configuration Build (GNU) for project Dev ****
ndk-build 
make: *** No rule to make target `jni/com_pkgpub_Dev.c', needed by `obj/local/armeabi/objs/dev/com_pkgpub_Dev.o'.  Stop.
**** Build Finished ****

From this message it sounds like some parameter should be missing from the file /jni/Android.mk:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS    := -DHAVE_INTTYPES_H
LOCAL_MODULE    := dev
LOCAL_SRC_FILES := com_pkgpub_Dev.c Dev.c
include $(BUILD_SHARED_LIBRARY) 

To solve it, it is just necessary to create the missing file "jni/com_pkgpub_Dev.c". This file content should be manually made based on the automatic generated code contained in the file "jni/com_pkgpub_Dev.h".

Now, it works!



来源:https://stackoverflow.com/questions/9313197/android-ndk-eclipse-parameter-and-javah

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