• 定义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. Applese 涂颜色(python解法)

    链接:https://ac.nowcoder.com/acm/contest/330/E 来源:牛客网 题目描述 精通程序设计的 Applese 叕写了一个游戏. 在这个游戏中,有一个 n 行 m 列 ...

  2. 杭电ACM hdu 2079 选课时间 (模板)

    Problem Description 又到了选课的时间了,xhd看着选课表发呆,为了想让下一学期好过点,他想知道学n个学分共有多少组合.你来帮帮他吧.(xhd认为一样学分的课没区别) Input输入 ...

  3. bs4的简单使用

    一.使用流程 解析流程: 1.pip install bs4 2.导包:from bs4 import BeautifulSoup 3.实例化一个BeautifulSoup对象(将页面源码数据加载到该 ...

  4. 微软原版SQL Helper

    代码 Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-- ...

  5. 9.ORM数据访问

    1.Spring对ORM的支持 ORM : 对象关系映射(Object Relational Mapping)是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术基于ORM的数据持久层框架有: ...

  6. Python模块:operator简单介绍

    Python官方文档地址:https://docs.python.org/3.6/library/operator.html?highlight=operator Operator提供的函可用于对象比 ...

  7. java——HashMap、Hashtable

    Map:类似Python的字典 HashMap: 不支持线程的同步,即同一时刻不能有多个线程同时写HashMap: 最多只允许一条记录的键值为null,不允许多条记录的值为null HashMap遍历 ...

  8. 自定义element-ui主题

    自定义element主题颜色:主要参考这个文章https://blog.csdn.net/wangcuiling_123/article/details/78513245,再自己做了一遍成功.感谢. ...

  9. 卸载3DSMAX

    AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...

  10. LitJson(读Exce文件写入到json文件):

    读Exce文件写入到json文件汇总: //命名空间 using System.Collections; using System.Collections.Generic; using System. ...