在Eclipse下使用C/C++ (JNI)最简单的方式

标签: jnieclipseapplicationtoolsdocumentationbuild
1267人阅读 评论(0) 收藏 举报
分类:

在网上看了很多资料实现JNI,可谓花样百出,其实android自身已经提供了最好的实现方法,NDK 
NDK 下载: 
http://developer.android.com/sdk/ndk/index.html

NDK的使用也很简单。我把它分为两步。
第一步,产生.h头文件,并根据此头文件写.C/.CPP文件
我们需要在.java中将相应method声明为native,具体可参考 http://marakana.com/forums/android/examples/49.html


第二步,将.C/.CPP编译成最终我们工程能接受的库文件,这就要用到NDK了
官方指导如下

Here's the general outline of how you work with the NDK tools:

  1. Place your native sources under <project>/jni/...
  2. Create <project>/jni/Android.mk to describe your native sources to the NDK build system
  3. Optional: Create <project>/jni/Application.mk.
  4. Build your native code by running the 'ndk-build' script from your project's directory. It is located in the top-level NDK directory:
    cd <project>
    <ndk>/ndk-build
    

    The build tools copy the stripped, shared libraries needed by your application to the proper location in the application's project directory.

  5. Finally, compile your application using the SDK tools in the usual way. The SDK build tools will package the shared libraries in the application's deployable .apk file.

For complete information on all of the steps listed above, please see the documentation included with the NDK package.



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:621576次
    • 积分:7529
    • 等级:
    • 排名:第2855名
    • 原创:91篇
    • 转载:106篇
    • 译文:0篇
    • 评论:258条
    新书上市,让大家久等了~
    讨论/学习

    QQ群(专注于Android系统的分析与讨论)组: 188145016


    Email: xuesenlin1@gmail.com

    博客专栏
    文章分类
    最新评论