Coder Social home page Coder Social logo

ndkdemo's Introduction

NDK开发笔记

写在前面:

  • 创建项目 不能勾选 include c++ 血泪教训
  • 保证本地的NDK环境已经搭建完成,随便执行$ ndk-build 一般只要不报找不到命定都是可以的

###Step 无脑式教程送上

  1. 新建一个项目,创建一个Java类,JNIUtil.java

  1. buildProject 此时在app/build/intermediates/classes/{包名}/目录下生成JNIUtil.class

  1. 通过javah 命令生成JNIUtil对应的头文件 ,打开terminal 进入app/build/intermediates/classes/执行 javah -jni {包名}JNIUtil 此时在 app/build/intermediates/classes/ 会生成一个对应的.h 文件

4.app/src/main 下创建一个文件夹 jni 并把 刚刚生成的.h文件移动过去,同时在此文件夹下面创建一个JNIUtil.c的文件 在文件中include 之前的头文件, 并且实现 头文件的方法。

  1. 接下来在app module目录下的build.gradle中设置库文件名(生成的so文件名)。找到gradle文件的defaultConfig这项,在里面添加如下内容:

  1. so生成完成即可使用 ,通过 以下方式引入 即可调用方法了

    static{ System.loadLibrary("libLib");// 你的so文件名字。 }

  2. 在项目的 gradle.properties 文件的末尾添加如下代码:解决ndk提示版本低不能自动编译jni

    android.useDeprecatedNdk=true 最后编译运行。

参考1 参考2

ndkdemo's People

Contributors

guider avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.