标签 ndk 下的文章

NDK-JNI开发笔记


2016/04/13

hello-jni项目(基于android studio 2.0)

(as2.2+ 可以用cmake 其实现,非常简单 不用.h文件 一开始的配置见 http://tools.android.com/tech-docs/external-c-builds 后面只要写个native方法 c文件中写对应的函数即可 )

  • 配置NDK 如果没下载NDK的话

    File->Settings Appearance & Behavior->System Settings ->Android SDK 右侧选择SDK Tools 勾选NDK更新 勾上更新重启项目。

local.properties里面如果没自动配置的话就这样配置(按上述步骤安装ndk 其目录就在sdk下)

## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Wed Apr 13 00:40:11 CST 2016
ndk.dir=E\:\\BaiduYunDownload\\adt-bundle-windows-x86_64-20140702\\sdk\\ndk-bundle
sdk.dir=E\:\\BaiduYunDownload\\adt-bundle-windows-x86_64-20140702\\sdk
  • 新建Project,一个Activity(xml中带一个TextView)
  • 新建一个NdkJniUtils类 声明原生方法getCString();

    public class NdkJniUtil { public native String getCString(); }

  • 生成C/C++ 头文件

法1: IDE:Build->MakeProject 得到class 编译之后的class在目录下