Ubuntu NDK配置与JNI demo
NDK配置
1.下载最新版本NDK(android-ndk-r9d-linux-x86_64.tar.bz2)
下载网页:http://developer.android.com/tools/sdk/ndk/index.html
2.拷贝下载文件到环境配置目录解压,解压方式
tar -jxvf android-ndk-r9d-linux-x86_64.tar.bz2
3.控制台进入到账户根目录,编辑.bashrc文件(vi .bashrc)
4.新建环境变量(主要最后一个文件夹为ndk解压后的文件夹名)
export NDK_HOME=/home/lchd/work/tools/android-ndk-r9-linux
5.在PATH中添加改环境
export PATH=$PATH:$NDK_HOME:.
6.退出控制台,重新进入控制台
输入 ndk-build 查看错误提示
Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
出现以上错误,恭喜你,环境配置OK
JNI demo
src源代码结构图
./src
├── ./src/com
│ └── ./src/com/example
│ └── ./src/com/example/testedittext
│ └── ./src/com/example/testedittext/MainActivity.java
└── ./src/jni
└── ./src/jni/helloworld.java
/src/com/example/testedittext/MainActivity.java
package com.example.testedittext; import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.Toast; import jni.helloworld; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
System.loadLibrary("helloworld");
Toast.makeText(this, "xx " + new helloworld().dispHelloWorld(), Toast.LENGTH_SHORT).show();
} @Override
public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }
/src/jni/helloworld.java
package jni;
public class helloworld {
public native String dispHelloWorld();
}
JNI文件目录
├── ./jni
│ ├── ./jni/Android.mk
│ └── ./jni/helloworld.c
/jni/Android.mk
# Copyright (C) 2009 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 := helloworld
LOCAL_SRC_FILES := helloworld.c include $(BUILD_SHARED_LIBRARY)
/jni/helloworld.c
#include <jni.h>
#include <stdio.h>
JNIEXPORT jstring JNICALL Java_jni_helloworld_dispHelloWorld(JNIEnv *env,
jobject obj) {
char* cstr = "helloworld111";
return (**env).NewStringUTF(env, cstr);
}
在项目根目录运行ndk-build 生成以下文件
├── ./libs
│ ├── ./libs/android-support-v4.jar
│ └── ./libs/armeabi
│ └── ./libs/armeabi/libhelloworld.so
├── ./obj
│ └── ./obj/local
│ └── ./obj/local/armeabi
│ ├── ./obj/local/armeabi/libhelloworld.so
│ └── ./obj/local/armeabi/objs
│ └── ./obj/local/armeabi/objs/helloworld
│ ├── ./obj/local/armeabi/objs/helloworld/helloworld.o
│ └── ./obj/local/armeabi/objs/helloworld/helloworld.o.d
运行android程序,正确谈出toast xx helloworld111.
Ubuntu NDK配置与JNI demo的更多相关文章
- android JNI 简单demo(2)它JNI demo 写
android JNI 简单demo(2)它JNI demo 写 一.搭建Cygwin 环境:http://blog.csdn.net/androidolblog/article/details/25 ...
- Ubuntu TensorFlow 源码 Android Demo的编译运行
Ubuntu TensorFlow 源码 Android Demo的编译运行 一. 安装 Android 的SDK和NDK SDK 配置 A:下载 国内下载地址选最新的: SDK: https://d ...
- NDK工具开发Jni,Android studio jni开发
NDK工具开发JNI 对于JNI的作用,我这边就不详细说明了,百度google 有很多这样的介绍,这边着重详解AS使用NDK工具开发,调C的流程. 1,创建工程 2,创建native方法 //该类的路 ...
- Android studio 使用NDK工具实现JNI编程
前言: Android开发中常常会使用到第三方的.so库.在使用.so库的时候就要用到JNI编程.JNI是Java Native Interface的缩写.它提供了若干的API实现了Java和其它语言 ...
- ubuntu下配置apache2多域名(apache2.4.6)
Ubuntu 在 Linux 各发行版中, 个人用户数量最多的. 很多人在本机和虚拟机中使用. 但 Ubuntu 和 Redhat 的 VirtualHost 设置方法不相同. 1. 打开目录 /et ...
- Eclipse NDK 配置,无需安装Cygwin
Eclipse NDK 配置,不用安装Cygwin 文章转自http://www.cnblogs.com/chenjiajin/archive/2012/04/12/2444188.html 一.关于 ...
- NDK配置
NDK 配置 Android SDK中下载NDK, LLDB Android.mk 和 Application.mk 简单来说 Android.mk 用来描述需要生成哪些模块的 .so 文件 Appl ...
- Cocos2d-x 2.2.3 使用NDK配置编译环境
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/wwj_748/article/details/30072379 Cocos2d-x 2.2.3 使用 ...
- Ubuntu系统---配置OpenCV
Ubuntu系统---配置OpenCV 目录 一.Ubuntu下配OpenCV 二.Ubuntu下配python-opencv 说明 上述一.二两种方式,配置OpenCV还是有区别的.按个人已有知 ...
随机推荐
- Eclipse + Apache Axis2 发布RESTful WebService(二)配置开发环境
1. 下载axis2相关软件地址:http://axis.apache.org/axis2/java/core/download.html 2. 安装插件:将axis2-eclipse-codegen ...
- Linux目录结构简析
Linux目录结构简析 Linux继承了unix操作系统结构清晰的特点.在linux下的文件结构非常有条理.但是,上述的优点只有在对linux相当熟悉时,才能体会到.现在,虫虫就把linux下的目录结 ...
- bzoj 2791 [Poi2012]Rendezvous 基环森林
题目大意 给定一个n个顶点的有向图,每个顶点有且仅有一条出边. 对于顶点i,记它的出边为(i, a[i]). 再给出q组询问,每组询问由两个顶点a.b组成,要求输出满足下面条件的x.y: 从顶点a沿着 ...
- LFYZOJ 104 Counting Swaps
题解 #include <iostream> #include <cstdio> #include <algorithm> #include <cmath&g ...
- 常用的XMPP服务器
1. Openfire (Wildfire) 3.x 底层通讯采用的mina框架,minak框架其实性能一般,netty早已经超越它,虽然最初都是Doug Lea写的.3.4版本之后支持集群,单台服务 ...
- 递归,回溯,DFS,BFS的理解和模板
LeetCode 里面很大一部分题目都是属于这个范围,例如Path Sum用的就是递归+DFS,Path Sum2用的是递归+DFS+回溯 这里参考了一些网上写得很不错的文章,总结一下理解与模板 递归 ...
- js-在url后面添加时间戳清除浏览器打开页面的缓存
这个解决办法还是在网上搜出来的,我还没有测试呢: 我有想既然可以添加时间戳,那可以添加随机数吗?我感觉是可以的,尽管没有测试过. 2018-3-13 几天前我就这个问题询问过我们的后台,加时间戳能否真 ...
- GitBook一个专注于帮助文档的工具
官网:https://www.gitbook.com GitHub组织:https://github.com/gitbookio GitBook一个专注于帮助文档的工具,比如: 1.简单的左侧列表右侧 ...
- 《SQL Server 监控和诊断》
http://jimshu.blog.51cto.com/ http://www.mssqlmct.cn/
- javascript好文 --- 深入理解可视区尺寸client
可视区大小 可视区大小client又称为可见大小或客户区大小,指的是元素内容及其内边距所占据的空间大小 clientHeight clientHeight属性返回元素节点的可见高度 clientHei ...