• 定义wrap类,声明native函数,加载库
package com.ndk.hello;

public class Classs {

    public native String say_hello();
static
{
System.loadLibrary("HelloAndroidNDK");
}
}
  • 在项目根目录创建jni文件夹,在此文件夹生成JNI头文件
javah -classpath ../bin/classes com.ndk.hello.Classs
  • 为生成的com_ndk_hello_Classs.h写实现文件
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_ndk_hello_Classs */ #ifndef _Included_com_ndk_hello_Classs
#define _Included_com_ndk_hello_Classs
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_ndk_hello_Classs
* Method: say_hello
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_com_ndk_hello_Classs_say_1hello
(JNIEnv *, jobject); #ifdef __cplusplus
}
#endif
#endif
#include "com_ndk_hello_Classs.h"

JNIEXPORT jstring JNICALL Java_com_ndk_hello_Classs_say_1hello(JNIEnv * env, jobject this)
{
return (*env)->NewStringUTF(env,"Hello Java NDK!");
}
  • 在jni文件夹写Android.mk文件
# Copyright (C)  The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := HelloAndroidNDK
LOCAL_SRC_FILES := com_ndk_hello_Classs.c include $(BUILD_SHARED_LIBRARY)
  • 在jni文件夹中交叉编译mk文件
$NDK/ndk-build
  • 将生成libs/armeabi/libHelloAndroidNDK.so文件
  • 编写安卓框架程序,调用native方法。
package com.ndk.hello;
import com.ndk.hello.Classs;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView; public class HelloAndroidNDK extends Activity{
@Override
public void onCreate(Bundle s)
{
super.onCreate(s); Classs c = new Classs(); String say = c.say_hello();
TextView tv = new TextView(this);
tv.setText(say);
setContentView(tv);
}
}

安卓NDK流程的更多相关文章

  1. EClipse开发NDK流程

    EClipse开发NDK流程(现在studio也在2.2之后支持了非常简单,只要创建项目的时候勾选c++支持就可以了)   什么情况下使用ndk,1.保护代码,java很容易反编译,c/c++反汇编比 ...

  2. 如何做个简单安卓App流程

    有同学做毕业设计,问怎样做个简单安卓App流程,我是做服务端的,也算是经常接触app,想着做app应该很简单吧,不就做个页面,会跳转,有数据不就行了,我解释了半天,人家始终没听懂,算了,我第二天问了下 ...

  3. 开发安卓安装流程(codorva+ionic)

    开发安卓安装流程 0 安装操作系统  Win10   用户名称尽量英文字母加数字,避免编码问题 1 安装Java sdk 1.8.0_45   所需文件 jdk-8u45-windows-x64 1. ...

  4. 完整版unity安卓发布流程(包括SDK有原生系统依赖关系的工程)

    要3个东西!NDS,SDK,JDK, NDK官网下载:https://developer.android.google.cn/ndk/downloads/index.html(注意系统是不是64位) ...

  5. 安卓ndk参考资料

    http://developer.samsung.com/technical-doc/view.do;jsessionid=xKa-L5xQDvdrSyc1sN71lHAXjcv2YUH7I92zjH ...

  6. [lua]安卓ndk如何编译lua库

    这里说的lua库是标准lua库,不包含tolua,不包含cocos2dx的各种lua扩展,是干净的lua. 参考: http://stackoverflow.com/questions/1229965 ...

  7. 网页打包安卓APP流程

    搭建环境过程: 1. 安装JDK. 参见http://www.cnblogs.com/Li-Cheng/p/4334985.html. 注:实质上到该网址上下载好JDK安装包,安装后添加一个环境变量: ...

  8. 安卓ndk 忽略 error: undefined reference to '找不到符号

    最近在搞天使之翼的mrp模拟器... 移到AndroidStudio了,现在想把原来的Android .mk那种方式的改成cmake的方式编译,但是编译时有一些符号找不到. undefined ref ...

  9. Linux下安卓ndk混合编译调用so方法——QuickStart学习

    转自:http://www.52pojie.cn/thread-313869-1-1.html #注意:.h 和.c中的错误eclipse不会检查,只会调用时在手机或虚拟机中死掉.因此需要仔细检查其中 ...

随机推荐

  1. Margarite and the best present

    Little girl Margarita is a big fan of competitive programming. She especially loves problems about a ...

  2. day_03 字符串

    1.python基础数据类型 1.int整数 2.str 字符串.(不会用字符串保存大量数据) 3.bool 布尔值. TRUE,FALSE 4.list 列表(重点) 存放大量数据 用[]表示 5. ...

  3. js遍历table和gridview

    //遍历table var tableObj = document.getElementById("tableName");var str = "";for(v ...

  4. 8.Spring对JDBC的支持和事务

    1.Spring对JDBC的支持 DAO : Spring中对数据访问对象(DAO)的支持旨在简化Spring与数据访问技术的操作,使JDBC.Hibernate.JPA和JDO等采用统一的方式访问 ...

  5. Linux中的netstat命令详解

    功能说明 netstat是基于Netstat这个命令行工具的指令,它可以用来查询系统上的网络套接字连接情况,包括tcp,udp以及Unix套接字:另外它还能列出路由表,接口状态和多播成员等信息. 主要 ...

  6. SVN更改通知的工具commitmonitor

    SVN更改通知的工具commitmonitor 下载地址: https://sourceforge.net/projects/commitmonitor/files/latest/download 工 ...

  7. 【ACM】N皇后问题

    N皇后问题 #include <iostream> #include <cmath> using namespace std; ; //判断当前位置的皇后加入是否成立 bool ...

  8. vue的watch详细用法

    https://www.cnblogs.com/shiningly/p/9471067.html https://www.jb51.net/article/139282.htm

  9. Python + Selenium 练习篇 - 获取页面所有邮箱

    代码如下: # coding=utf-8import re    #python中利用正则,需要导入re模块from selenium import webdriverdriver = webdriv ...

  10. 安装Python + Selenium

    1.Python下载与安装‍ 先去Python官网下载安装包:http://www.python.org/ 下载后按步骤安装(最好不要安装到系统盘) 安装好后将安装路径(Python和Scripts) ...