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

在网上看了很多资料实现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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值