06_锅炉压力案例_progressbar实现-LMLPHP

06_锅炉压力案例_progressbar实现-LMLPHP06_锅炉压力案例_progressbar实现-LMLPHP

06_锅炉压力案例_progressbar实现-LMLPHP

06_锅炉压力案例_progressbar实现-LMLPHP

相关的native方法可以用javah来生成一个头文件。拿着这个的MainActivity,用它来生成一个头文件。

06_锅炉压力案例_progressbar实现-LMLPHP

06_锅炉压力案例_progressbar实现-LMLPHP

Signature是当前这个方法的方法签名。() V全空参数返回的是void.

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_itheima_pressurediagram_MainActivity */ #ifndef _Included_com_itheima_pressurediagram_MainActivity
#define _Included_com_itheima_pressurediagram_MainActivity
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_itheima_pressurediagram_MainActivity
* Method: startMonitor
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_itheima_pressurediagram_MainActivity_startMonitor
(JNIEnv *, jobject); /*
* Class: com_itheima_pressurediagram_MainActivity
* Method: stopMonitor
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_itheima_pressurediagram_MainActivity_stopMonitor
(JNIEnv *, jobject); #ifdef __cplusplus
}
#endif
#endif

用插件指定一下我的include目录在什么位置上。

06_锅炉压力案例_progressbar实现-LMLPHP

06_锅炉压力案例_progressbar实现-LMLPHP

06_锅炉压力案例_progressbar实现-LMLPHP

06_锅炉压力案例_progressbar实现-LMLPHP

06_锅炉压力案例_progressbar实现-LMLPHP

06_锅炉压力案例_progressbar实现-LMLPHP

[2017-07-16 14:31:20 - Unable to launch cygpath. Is Cygwin on the path?] java.io.IOException: Cannot run program "cygpath": CreateProcess error=2, ϵͳÕҲ»µ½ָ¶

06_锅炉压力案例_progressbar实现-LMLPHP

06_锅炉压力案例_progressbar实现-LMLPHP

06_锅炉压力案例_progressbar实现-LMLPHP

接下来clean一下就好了

06_锅炉压力案例_progressbar实现-LMLPHP

**** Clean-only build of configuration Default for project JNIDay03_02_锅炉压力 ****

H:\NDK\android-ndk-r9d-windows-x86_64\android-ndk-r9d\ndk-build.cmd clean
Android NDK: WARNING: APP_PLATFORM android-18 is larger than android:minSdkVersion 8 in ./AndroidManifest.xml
[armeabi] Clean : pressure [armeabi]
[armeabi] Clean : stdc++ [armeabi] **** Build Finished **** 

06_锅炉压力案例_progressbar实现-LMLPHP

一些问题与解决方法:

问题一:Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 8 in ./AndroidManifest.xml    (这个是NDK工具的一个BUG,若build Target大于minSdkVersion,则会报这个错误,导致无法运行)
解决方法:
android-ndk-r8e/build/core/add-application.mk第128行把__ndk_warning改为__ndk_info;然后重新build一次项目即可消除错误。
原文:
this problem may be safely fixed by changing this line in add-application.mk from __ndk_warning to __ndk_info
链接:

https://code.google.com/p/android/issues/detail?id=39752

06_锅炉压力案例_progressbar实现-LMLPHP

APP_PLATFORM := android-
**** Build of configuration Default for project JNIDay03_02_锅炉压力 ****

H:\NDK\android-ndk-r9d-windows-x86_64\android-ndk-r9d\ndk-build.cmd all
[armeabi] Install : libpressure.so => libs/armeabi/libpressure.so **** Build Finished ****

06_锅炉压力案例_progressbar实现-LMLPHP

**** Clean-only build of configuration Default for project JNIDay03_02_锅炉压力 ****

H:\NDK\android-ndk-r9d-windows-x86_64\android-ndk-r9d\ndk-build.cmd clean
[armeabi] Clean : pressure [armeabi]
[armeabi] Clean : stdc++ [armeabi] **** Build Finished ****
05-13 00:42