Javah error when generating the. h file

Source: Internet
Author: User

Javah Error: Unable to access android.app.Activity, cannot find android.app.Activity class file  " Run TestJni1" or "Debug TestJni1", "D:\WORKSPACE\TESTJNI1\BIN\CLASSES\COM\EXAMPLE\TESTJNI1" will produce a lot of *.class files, Do the following for the "Mainactivity.class", according to which the required head file will be generated. But actually it doesn't work.

The following is the operation process ********************************************************
Microsoft Windows [version 6.1.7601]
Copyright (c) Microsoft Corporation. All rights reserved.

c:\users\administrator>D:

d:\>CD \workspace\testjni1\bin

d:\workspace\testjni1\bin>javah-d header-classpath classes-jni com.example.testjni1.MainActivity
Error: Unable to access android.app.Activity
The class file for android.app.Activity could not be found
The above is the operation process ********************************************************

According to the SRC record can also get the head file, I tried, is possible.

The following is the operation process ********************************************************
Microsoft Windows [version 6.1.7601]
Copyright (c) Microsoft Corporation. All rights reserved.

c:\users\administrator>D:

d:\>CD \workspace\testjni1\src
d:\workspace\testjni1\src>Javah com.example.testjni1.MainActivity

d:\workspace\testjni1\src>dir
The volume in drive D is not labeled.
The serial number of the volume is 000c-6d9f

Directory of D:\WORKSPACE\TESTJNI1\SRC

2013/03/09 10:57 <DIR>.
2013/03/09 10:57 <DIR>.
2013/03/09 10:38 <DIR> com
2013/03/09 10:57 726 com_example_testjni1_mainactivity.h
1 Files 726 bytes
3 Directories 10,670,010,368 bytes available

D:\workspace\testjni1\src>
The above is the operation process ********************************************************

This is actually a "D:\workspace\testjni1\src\com.example\testjni1\MainActivity.java" operation, you can get a ' com_example_ ' in the ' src ' catalogue. Testjni1_mainactivity.h "header file, but it's not a lot of stuff in this file.

The surest way to do this is to indicate the Android.jar path for Javah, which will be better.

The following is the operation process ********************************************************
Microsoft Windows [version 6.1.7601]
Copyright (c) Microsoft Corporation. All rights reserved.

c:\users\administrator>D:

d:\>CD Workspace\tstjni1\bin

d:\workspace\testjni1\bin>javah-d Heafer-classpath c:\adt-bundle-windows-x86_64\adt-bundle-windows-x86_ 64-20130219\sdk\platforms\android-17\android.jar;classes-jni com.example.testjni1.MainActivity

d:\workspace\testjni1\bin>dir
The volume in drive D is not labeled.
The serial number of the volume is 000c-6d9f

Directory of D:\workspace\testjni1\bin

2013/03/09 13:58 <DIR>.
2013/03/09 13:58 <DIR>.
2013/03/09 13:16 880 Androidmanifest.xml
2013/03/09 13:16 <DIR> Classes
2013/03/09 13:33 448,812 Classes.dex
2013/03/09 13:58 3,938 Com_example_testjni1_mainactivity.h
2013/03/09 13:33 <DIR> Dexedlibs
2013/03/09 13:39 <DIR> Header
2013/03/09 13:33 196,360 testjni1.apk
2013/03/09 13:33 <DIR> Res
2013/03/09 13:33 40,788 RESOURCES.AP_
5 Files 690,778 bytes
6 Directories 10,671,005,696 bytes available

D:\workspace\testjni1\bin>

The above is the operation process ********************************************************

"I solved the problem by the above method, the operation is as follows" ********************* START *********************************

Microsoft Windows [version 6.1.7601]
Copyright (c) Microsoft Corporation. All rights reserved.

C:\USERS\ADMINISTRATOR>CD.

C:\USERS>CD.

C:\>d:

D:\>CD D:\software\adt\android-ndk-r8d\samples\hello-jni

D:\software\adt\android-ndk-r8d\samples\hello-jni>javah-classpath bin/classes;d
: \software\adt\sdk\platforms\android-17\android.jar -D ndk com.example.hellojni.
Hellojni

D:\software\adt\android-ndk-r8d\samples\hello-jni>

END ************************************************

There's a lot more inside the head file this time.

The following is the first time the head file was ******************************************
/* Don't EDIT this file-it are machine generated */
#include <jni.h>
/* Header for class com_example_testjni1_mainactivity */

#ifndef _included_com_example_testjni1_mainactivity
#define _included_com_example_testjni1_mainactivity
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class:com_example_testjni1_mainactivity
* Method:add
* Signature: (II) I
*/
Jniexport Jint Jnicall Java_com_example_testjni1_mainactivity_add
(JNIEnv *, Jobject, Jint, Jint);

/*
* Class:com_example_testjni1_mainactivity
* Method:sub
* Signature: (II) I
*/
Jniexport Jint Jnicall java_com_example_testjni1_mainactivity_sub
(JNIEnv *, Jobject, Jint, Jint);

#ifdef __cplusplus
}
#endif
#endif
The above is the first to get the head file ******************************************

The following is the second acquisition of the head file ******************************************
/* Don't EDIT this file-it are machine generated */
#include <jni.h>
/* Header for class com_example_testjni1_mainactivity */

#ifndef _included_com_example_testjni1_mainactivity
#define _included_com_example_testjni1_mainactivity
#ifdef __cplusplus
extern "C" {
#endif
#undef com_example_testjni1_mainactivity_mode_private
#define Com_example_testjni1_mainactivity_mode_private 0L
#undef com_example_testjni1_mainactivity_mode_world_readable
#define Com_example_testjni1_mainactivity_mode_world_readable 1L
#undef com_example_testjni1_mainactivity_mode_world_writeable
#define Com_example_testjni1_mainactivity_mode_world_writeable 2L
#undef Com_example_testjni1_mainactivity_mode_append
#define Com_example_testjni1_mainactivity_mode_append 32768L
#undef com_example_testjni1_mainactivity_mode_multi_process
#define Com_example_testjni1_mainactivity_mode_multi_process 4L
#undef com_example_testjni1_mainactivity_mode_enable_write_ahead_logging
#define Com_example_testjni1_mainactivity_mode_enable_write_ahead_logging 8L
#undef com_example_testjni1_mainactivity_bind_auto_create
#define Com_example_testjni1_mainactivity_bind_auto_create 1L
#undef Com_example_testjni1_mainactivity_bind_debug_unbind
#define Com_example_testjni1_mainactivity_bind_debug_unbind 2L
#undef Com_example_testjni1_mainactivity_bind_not_foreground
#define Com_example_testjni1_mainactivity_bind_not_foreground 4L
#undef com_example_testjni1_mainactivity_bind_above_client
#define Com_example_testjni1_mainactivity_bind_above_client 8L
#undef com_example_testjni1_mainactivity_bind_allow_oom_management
#define Com_example_testjni1_mainactivity_bind_allow_oom_management 16L
#undef com_example_testjni1_mainactivity_bind_waive_priority
#define Com_example_testjni1_mainactivity_bind_waive_priority 32L
#undef com_example_testjni1_mainactivity_bind_important
#define Com_example_testjni1_mainactivity_bind_important 64L
#undef com_example_testjni1_mainactivity_bind_adjust_with_activity
#define Com_example_testjni1_mainactivity_bind_adjust_with_activity 128L
#undef Com_example_testjni1_mainactivity_context_include_code
#define Com_example_testjni1_mainactivity_context_include_code 1L
#undef com_example_testjni1_mainactivity_context_ignore_security
#define Com_example_testjni1_mainactivity_context_ignore_security 2L
#undef com_example_testjni1_mainactivity_context_restricted
#define Com_example_testjni1_mainactivity_context_restricted 4L
#undef com_example_testjni1_mainactivity_result_canceled
#define Com_example_testjni1_mainactivity_result_canceled 0L
#undef COM_EXAMPLE_TESTJNI1_MAINACTIVITY_RESULT_OK
#define COM_EXAMPLE_TESTJNI1_MAINACTIVITY_RESULT_OK-1L
#undef Com_example_testjni1_mainactivity_result_first_user
#define Com_example_testjni1_mainactivity_result_first_user 1L
#undef com_example_testjni1_mainactivity_default_keys_disable
#define Com_example_testjni1_mainactivity_default_keys_disable 0L
#undef Com_example_testjni1_mainactivity_default_keys_dialer
#define Com_example_testjni1_mainactivity_default_keys_dialer 1L
#undef com_example_testjni1_mainactivity_default_keys_shortcut
#define Com_example_testjni1_mainactivity_default_keys_shortcut 2L
#undef com_example_testjni1_mainactivity_default_keys_search_local
#define Com_example_testjni1_mainactivity_default_keys_search_local 3L
#undef Com_example_testjni1_mainactivity_default_keys_search_global
#define Com_example_testjni1_mainactivity_default_keys_search_global 4L
/*
* Class:com_example_testjni1_mainactivity
* Method:add
* Signature: (II) I
*/
Jniexport Jint Jnicall Java_com_example_testjni1_mainactivity_add
(JNIEnv *, Jobject, Jint, Jint);

/*
* Class:com_example_testjni1_mainactivity
* Method:sub
* Signature: (II) I
*/
Jniexport Jint Jnicall java_com_example_testjni1_mainactivity_sub
(JNIEnv *, Jobject, Jint, Jint);

#ifdef __cplusplus
}
#endif
#endif
The above is the second gain of the head file ******************************************

Two documents are obviously very different, but on the internet, we generally think that there is no difference between the two. That's all I can tell you--stop joking, okay?

Some questions when Android uses NDK to develop projects 1,
In the process of using the NDK, one step is to generate the corresponding. h file based on the generated. class file.
The web-related documentation is given by using the following command:
CD <project dir>
mkdir JNI
Javah-calsspath bin-d JNI <class>

That is, enter the project directory and create a JNI folder.
Then call the Javah command to generate the. h file from the. class file in the bin directory and place it in the Jni folder.
Note that the <class> here is specified in the form of the package name, the class name, and the package name cannot be omitted.
However, the following error occurred after running:
Error: Unable to access <class>
class file for <class> not found
Javadoc: Error-Class <class> not found.
Error: No classes were specified on the command line. Please try using-help.

It was later discovered that the generated. class file was not placed directly under the Bin folder, but rather contained a subdirectory named classes.
Therefore, replace the above command with the following:
Javah-calsspath bin/classes-D JNI <package>.<class>
"I also have this problem, through the above to change the" bin "to" bin/classes "to solve the problem "
2.
After running, the following error occurred:
Error: Unable to access <class>
Wrong class file: <class file>
Class file has the wrong version 50.0, should be 49.0
Either delete the file or make sure the file is in the correct classpath subdirectory.
Com.sun.tools.javac.util.Abort
At Com.sun.tools.javac.comp.Check.completionError (check.java:169)
At Com.sun.tools.javadoc.DocEnv.loadClass (docenv.java:149)
At Com.sun.tools.javadoc.rootdocimpl.<init> (rootdocimpl.java:77)
At Com.sun.tools.javadoc.JavadocTool.getRootDocImpl (javadoctool.java:156)
At Com.sun.tools.javadoc.Start.parseAndExecute (start.java:330)
At Com.sun.tools.javadoc.Start.begin (start.java:128)
At Com.sun.tools.javadoc.Main.execute (main.java:66)
At Com.sun.tools.javah.Main.main (main.java:147)
Javadoc: Error-fatal error

This error is caused by inconsistencies in the JDK version.
The JDK version used by Eclipse to create the. class file is 1.6, and the Run Javah command uses the 1.5 version.
Modify the method to set the JDK version in Eclipse, or you can modify the Java version of the system environment.
In summary, keep the versions of the JDK used by each command consistent.

3.
After writing the. C and Android.mk files according to the. h file, you need to compile the. So file through the NDK command.
You need to add the NDK installation directory to the environment variable and then execute the command ndk-build command under the JNI directory.
However, the following error is reported under the R7 version:
<ndk>/prebuilt/linux-x86/bin/awk: Unable to execute binary file
Android ndk:host ' awk ' tool is outdated. Please define Host_awk ...
<ndk>/build/core/init.mk:258: * * * Android ndk:aborting. 。 Stop it.

This error is due to the awk command in the NDK package that does not match my current system version.
If the system itself has an awk command, simply delete or rename the <ndk>/prebuilt/linux-x86/bin/awk.

4.
If the. So file compiles successfully, the folder Libs/armeabi is generated under the project directory, and the corresponding. So file is in this directory.
When you package the APK, the directory is automatically included to ensure that the appropriate library is found when the program executes.
However, when I run the resulting apk, I get an error and I'm not prompted to find the library:
Java.lang.UnsatisfiedLinkError:Couldn ' t load <so>: Findlibrary returned null
At Java.lang.Runtime.loadLibrary (runtime.java:429)
At Java.lang.System.loadLibrary (system.java:554)

This error is due to the fact that the name of the library is regular.
When defining the name of the library through Local_module in the Android.mk file, do not prefix lib and suffix.
When you build the. So file, the prefix lib and suffix are added automatically.
When calling System.loadlibrary () in Java, the parameters are consistent with the name defined by Local_module.
Also, if you add the prefix lib when you define Local_module, the prefix lib is not added again when you generate the. so file.
At this point, the automatically generated. So file is only one suffix more than the definition.
In Java, however, it is still not prefixed with LIB, which is the same case when the local_module is not prefixed.

"Turn from" http://hi.baidu.com/gaogaf/item/c20d5abf1a073b42bb0e1277

"Turn from" http://blog.163.com/xdma_tw/blog/static/16610932920132910513108/

Javah error when generating the. h file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.