Git Product home page Git Product logo

ndkdemo's Introduction

NDKdemo

Android studio中NDK的开发例子

1、开发环境

● Android Studio 2.0.0 ● android-ndk-r10e ● gradle 2.10

##2、然后我们打开gradle.properties文件, 在文件的尾端写一句, 如果没有写这一句会编译不通过 android.useDeprecatedNdk=true

##3.在defaultConfig配置

ndk{ moduleName "ndk-test" //要引用module的名字 ldLibs "log" //引用库的名字(选填) abiFilters "armeabi" //配置需要编译出那些版本的so库(如果不写,就编译出所有版本的so库) } ##4.创建一个Test类 public class NDKTest{ public static natvie int add(int i,int j); static{ System.loadLibrary("ndk-test"); } }

##5 生成Java_com_lidong_demo_ndkdemo_NdkTest_add.h文件 命令行:javah -d ... 生成文件 /* DO NOT EDIT THIS FILE - it is machine generated / #include <jni.h> / Header for class com_lidong_demo_ndkdemo_NdkTest */

#ifndef _Included_com_lidong_demo_ndkdemo_NdkTest #define _Included_com_lidong_demo_ndkdemo_NdkTest #ifdef __cplusplus extern "C" { #endif /*

  • Class: com_lidong_demo_ndkdemo_NdkTest
  • Method: add
  • Signature: (II)Ljava/lang/String; */ JNIEXPORT jint JNICALL Java_com_lidong_demo_ndkdemo_NdkTest_add (JNIEnv *, jclass, jint, jint); #ifdef __cplusplus } #endif #endif

##6实现Java_com_lidong_demo_ndkdemo_NdkTest_add.文件

// // Created by dong on 2016/4/3. //

#include<com_lidong_demo_ndkdemo_NdkTest.h>

JNIEXPORT jint JNICALL Java_com_lidong_demo_ndkdemo_NdkTest_add (JNIEnv *evn, jclass cla, jint i, jint j){ return i+j; } ##7.最后在调用。 text.setText("计算1+2的结果"+NdkTest.add(1,2)+"");;

##8效果效果

ndkdemo's People

Contributors

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