Cmake编写JNI
调用两个库
CMakeLists.txt
//把那种大段的注释去掉了
cmake_minimum_required(VERSION 3.4.)
add_library( # Sets the name of the library.
native-lib # Sets the library as a shared library.
SHARED # Provides a relative path to your source file(s).
src/main/cpp/native-lib.cpp ) add_library( # Sets the name of the library.
nativeSecond-lib # Sets the library as a shared library.
SHARED # Provides a relative path to your source file(s).
src/main/cpp/nativeSecond-lib.cpp )
find_library( # Sets the name of the path variable.
log-lib # Specifies the name of the NDK library that
# you want CMake to locate.
log )
target_link_libraries( # Specifies the target library.
native-lib # Links the target library to the log library
# included in the NDK.
${log-lib} ) target_link_libraries( # Specifies the target library.
nativeSecond-lib # Links the target library to the log library
# included in the NDK.
${log-lib} )
native-lib.cpp
#include <jni.h>
#include <string> extern "C"
JNIEXPORT jstring JNICALL
Java_com_example_aplex_cantest_MainActivity_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
}
nativeSecond-lib.cpp
#include <jni.h>
#include <string> extern "C"
JNIEXPORT jstring JNICALL
Java_com_example_aplex_cantest_MainActivity_stringFromJNI22(
JNIEnv *env,
jobject /* this */) {
std::string hello = "Hello Second from C++";
return env->NewStringUTF(hello.c_str());
}
MainActivity.java
package com.example.aplex.cantest; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView; public class MainActivity extends AppCompatActivity { // Used to load the 'native-lib' library on application startup.
static {
System.loadLibrary("native-lib");
System.loadLibrary("nativeSecond-lib");
}
Button bt;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); // Example of a call to a native method
tv = (TextView) findViewById(R.id.sample_text);
tv.setText(stringFromJNI()); bt = (Button)findViewById(R.id.bt);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tv.setText(stringFromJNI22());
}
});
} /**
* A native method that is implemented by the 'native-lib' native library,
* which is packaged with this application.
*/
public native String stringFromJNI();
public native String stringFromJNI22();
}




Cmake编写JNI的更多相关文章
- Android JNI编程(八)——体验AS2.2.2编写Jni程序、Java调C、C调Java函数、将C代码中的Log打印至Logcat
版权声明:本文出自阿钟的博客,转载请注明出处:http://blog.csdn.net/a_zhon/. 目录(?)[+] 不得不说在AS2.2以上的版本进行开发就一个字——爽,在2.0上使用jni出 ...
- JNI技术基础(2)——从零开始编写JNI代码
书接上文: <JNI技术基础(1)——从零开始编写JNI代码> 2.编译源程序HelloWorld.java并生成HelloWorld.class 3.生成头文件HelloWorld.h ...
- 技术转载:Jni学习四:如何编写jni方法
转载:http://blog.chinaunix.net/u1/38994/showart_1099528.html 一.概述: 在这篇文章中将会简单介绍如何编制一些简单的JNI 方法.我们都知道JN ...
- 在Ubuntu为Android硬件抽象层(HAL)模块编写JNI方法提供Java访问硬件服务接口(老罗学习笔记4)
在上两篇文章中,我们介绍了如何为Android系统的硬件编写驱动程序,包括如何在Linux内核空间实现内核驱动程序和在用户空间实现硬件抽象层接口.实现这两者的目的是为了向更上一层提供硬件访问接口,即为 ...
- 为Android硬件抽象层(HAL)模块编写JNI方法提供Java访问硬件服务接口
在上两篇文章中,我们介绍了如何为Android系统的硬件编写驱动程序,包括如何在Linux内核空间实现内核驱动程序和在用户空间实现硬件抽象层接 口.实现这两者的目的是为了向更上一层提供硬件访问接口,即 ...
- Android Studio 编写 JNI
之前一直都不知怎么编写JNI,今天刚好学习一下,感谢梦真的指教,以及提供的文档. 参考链接 http://blog.csdn.net/u011168565/article/details/518781 ...
- JNI技术基础(1)——从零开始编写JNI代码
众所周知,Java程序的最大特点就是其跨平台的特性,编写的上层应用程序可以不加任何修改甚至不用重新编译而运行于不同的平台上,然而,Java本身也存着这一个弊端,那就是性能上相对要差一些,在对性能要求比 ...
- 【转载】cmake编写
Cmake的输入是在源码目录下的CMakeLists.txt文件.这个文件可以用include或者 add_subdirectory 命令增加入其它的输入文件. 语法 CMakeList.txt文件是 ...
- Android(java)学习笔记261:JNI之编写jni程序适配所有处理器型号
1. 还是以"02_两个数相加"为例,你会发现这个jni程序只能在ARM处理器下运行,如下: 如果我们让上面的程序运行在x86模拟器上,处理平台不对应,报如下错误: 03-29 ...
随机推荐
- Dalsa线扫相机SDK下载和安装
1.首先去官方网站下载SDK Support Downloads - Teledyne DALSA http://www.teledynedalsa.com/imaging/support/downl ...
- ASP.NET MVC 全局异常
先新建一个过滤器ExceptionHandleErrorAttribute.cs 内容如下: using System; using System.Net; using System.Web; usi ...
- mysql数据库binlog日志的异地备份
MySQL数据库的二进制日志binlog记录了对数据库的全量DDL和DML操作,对数据库的point to point灾难恢复起着无法替代的关键作用.因此,基于此类考虑,需要对生产环境产生的binlo ...
- Get Requests with Json Data && Get Requests with Url Parameters
- Storm的并行度
在Storm集群中,运行Topolopy的实体有三个:工作进程,executor(线程),task(任务),下图可以形象的说明他们之间的关系. 工作进程 Storm集群中的一台机器会为一个或则多个To ...
- nodejs改变代码不需要重启的方法
1.node 搭建本地服务器 在F:/node文件夹下新建app.js const http = require('http'); http.createServer((req, res) => ...
- [Swift实际操作]七、常见概念-(2)点CGPoint和变形CGAffineTransform的使用
本文将为你演示点对象CGPoint的使用,其中CG表示来自CoreGraphic(核心图形)这个跨平台框架 首先导入需要使用的两个框架第一个框架表示界面工具框架第二个框架表示核心绘图和动画框架 imp ...
- 数据结构---散列表查找(哈希表)概述和简单实现(Java)
散列表查找定义 散列技术是在记录的存储位置和它的关键字之间建立一个确定的对应关系f,是的每个关键字key对应一个存储位置f(key).查找时,根据这个确定的对应关系找到给定值的key的对应f(key) ...
- (转)如何修改windows下mysql的字符集
原文:http://blog.csdn.net/yjz_sdau/article/details/52135050 (1) 最简单的修改方法,就是修改mysql的my.ini文件中的字符集键值, 如 ...
- 原生JavaScript的DOM操作方法总结
什么是DOM? DOM即文档对象模型,Document Object Model. 是HTML和XML文档的编程接口.它提供了对文档的结构化的表述,并定义了一种方式可以使从程序中对该结构进行访问,从 ...