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还是有区别的.按个人已有知 ...
随机推荐
- RestAssured打印日志到文件中的方法
参考https://stackoverflow.com/questions/14476112/how-to-get-rest-assured-log-into-something-printable- ...
- hdu 3625 Examining the Rooms 轮换斯特林数
题目大意 n个房间对应n把钥匙 每个房间的钥匙随机放在某个房间内,概率相同. 有K次炸门的机会,求能进入所有房间的概率 一号门不给你炸 分析 我们设\(key_i\)为第i间房里的钥匙是哪把 视作房间 ...
- hdu 3320 计算几何(三维图形几何变换)
openGL Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- ubuntu16.04安装ibus中文输入法
按照网上给的安装方法,没成功,在切换ibus的时候总是报错,记录下解决办法. 安装语言包 System Settings–>Language Support–>Install/Remove ...
- 【leetcode】 First Missing Positive
[LeetCode]First Missing Positive Given an unsorted integer array, find the first missing positive in ...
- iOS上实现圆角图片
UIImageView自带 //圆角设置 imageView.layer.cornerRadius = ;(值越大,角就越圆) imageView.layer.masksToBounds = YES; ...
- MVC中使用ajax传递json数组
解决方法 去www.json.org下载JSON2.js再调用JSON.stringify(JSONData)将JSON对象转化为JSON串. var people = [{ "UserNa ...
- 对农行金e顺k令的一些猜测
手上有一个未激活的农行金e顺k令 开机后要求输入12位的激活码,随机输入多次,均告失败 花了点时间猜想k令的工作模式: 已知: k令无法联网,出厂后除了输入激活码的机会外,无法获取任何信息 k令内部有 ...
- js遍历map匹配数据和js遍历数组匹配map数据
var __LocalDataCities = { list: { "010": ["北京", "BEIJING"], "0100 ...
- IntelliJ IDEA中Spring Boot项目使用spring-boot-devtools无法实现热部署/热更新的问题解决
这个设置真的和Eclipse有很大区别,Eclipse中只要运行之后就可实现修改文件自动重启.但IDEA不太一样,需要做如下配置: 前提: 1.添加spring-boot-devtools到POM. ...