android开发手记一_ndk编程实例

上传人:marr****208 文档编号:117195313 上传时间:2019-11-18 格式:DOC 页数:17 大小:42KB
返回 下载 相关 举报
android开发手记一_ndk编程实例_第1页
第1页 / 共17页
android开发手记一_ndk编程实例_第2页
第2页 / 共17页
android开发手记一_ndk编程实例_第3页
第3页 / 共17页
android开发手记一_ndk编程实例_第4页
第4页 / 共17页
android开发手记一_ndk编程实例_第5页
第5页 / 共17页
点击查看更多>>
资源描述

《android开发手记一_ndk编程实例》由会员分享,可在线阅读,更多相关《android开发手记一_ndk编程实例(17页珍藏版)》请在金锄头文库上搜索。

1、Android开发手记一_NDK编程实例A Android Development Notes- NDK programming examplesOn Android, most of the application development is based on the Java language. To use C or c+ programs or libraries, you need to use NDK to implement. NDK is the abbreviation of Native Development Kit. It is a set of tools, int

2、egrated Android cross compiler environment, and provides a more convenient Makefile, can be C+ dynamic library to help developers to quickly develop C or, and automatically will be packaged into APK so and Java program, run in Android.OK, lets talk less. Lets explain the application of NDK with a si

3、mple example.First, build the development environmentAlthough this step does not have any technical content, but for beginners, there is a good guide to entry, or very helpful.1.1 Android SDK buildFirst of all, to develop Android programs, Androids SDK must be installed. Of course, the Java environm

4、ent is also essential. Well have to install JDK and Eclipse first, and this can choose a newer version, because the new Android in SDK is no longer in favor of the old version.1.1.1 JDK can use the V5 or V6 version to download the address http:/ Eclipse can use version version 3.4 or 3.5 download ad

5、dress, http:/www.eclipse.org/downloads/. Of course, if you need other Java development environment, you can not Eclipse, but it is not ADT (Android Development Tools) plug-in. Recommend or use Eclipse for development is better, after all, more authoritative and convenient?.1.1.3 install SDKThe Andro

6、id SDK download address is http:/ installs plug-in Eclipse for ADT. In Eclipse, fill in the update site https:/dl- and then select Install ADT.1.1.5 next, we select the Android platform and components. If in the window system, run SDK Setup.exe; if in the Linux system, run the tools directory under

7、the Android program, you can choose the required Android, Platform and components.After youve done that, you can develop the Android application. You can use Eclipse to create a Android project, a relatively simple Hello Android, and then run under the simulator. Specific operations, you can see the

8、 development of Android site instructions, there are detailed steps.1.2 Android NDK buildWe have built the SDK environment, you can develop Java applications. To develop C programs, you have to build NDK environments.NDK provides us with the following:Libc (C, Library) headersLibm (math, Library) he

9、adersJNI interface headersBZ (Zlib, compression) headersBlog (Android, logging) headerA, Minimal, set, of, headers, for, C+, supportInstallation of 1.2.1 NDKDownload the NDK installation package, download the address http:/ and use it after downloading.1.2.2 if youre in the Linux development environ

10、ment, then you can use it. In the window environment, you also need to install cygwin. Cygwin download address: http:/ this way, the NDK environment has been set up. Now lets do actual combat exercises.Two NDK development examplesWith regard to the use of NDK, you first need to understand a concept:

11、 JNI. What is JNI?2.1 Hello-jniThis is a NDK with examples of procedures, the official website of the installation instructions, step by step, what should be no problem, here not elaborate.2.2, My, God, I, did, itThe first step in learning is to imitate. We follow the example of Hello-jni above to c

12、reate our own NDK program. In this process, the related contents and concepts are analyzed and explained.First, create your own NDK project. We create our own myjni project in the NDK sample directory, and then in the sub folder, create a directory of JNI two and Src JNI, we used to put the C file,

13、SRC C database java interface file. Create a directory, and then create the file jni/myjni.c, the file is relatively simple, that is, output a string, the contents are as follows#include #include #include #include #define LOG_TAG MYJNI#define LOGI (.) _android_log_print (ANDROID_LOG_DEBUG, LOG_TAG,

14、_VA_ARGS_)Static char s_string = My God, I did it!;JstringJava_com_jpf_myjni_MyJNI_stringFromJNI (JNIEnv* env),Jobject thiz)LOGI (MyJNI is called!);Return (*env) -NewStringUTF (Env, s_string);The only thing this program is different from hello-jni is to refer to the header file. In the header file,

15、the function _android_log_print () is declared, and log can be output according to the different log levels, which facilitates debugging of the code. In NDK, printf () cannot output,So we need to use the log library to output what we need to output in our c code library through the Java console. Calling the f

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号