Code Monkey home page Code Monkey logo

jnidemo's Introduction

JNIDemo

##这只是一个简单的在AndroidStudio中书写及调用JNI的小demo

关于JDK ,AndroidSDK,NDK的配置此处略

1.创建JniUtils.java 类,生成并生成.h头文件

此类里代码很简单:


  public class JniUtils {
    static {
      System.loadLibrary("sayhello");
    }
    public native int secondTest(int a,int b);
    public native String sayHello();
  }

然后Build->Make Project,此时会在_app/build/intermediates/classes/debug/com/neopi/demo/jni/JniUtils.class_看到对应的class文件, 然后在终端,工作目录切换到java的统计目录,使用命令

javah -d jni -classpath /home/neopi/Documents/Demo_Workspace/Demo/app/build/intermediates/classes/debug com.neopi.demo.jni.JniUtils

注意debug 后面的空格,次命令执行结束后会在java的同级目录下生成一个jni文件夹,并生成名为com_neopi_demo_jni_JniUtils.h的头文件,

2.编写c文件 可以直接从刚才生成的头文件中复制对应的方法,实现即可,具体看代码.

3.Android项目调用 参考MainActivity.java代码.

关于生成头文件的命令可以使用IDE的 External Tools工具配置如图:

 External Tools

jnidemo's People

Contributors

neopi avatar

Watchers

 avatar  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.