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.

最新文章

  1. Mysql 存储引擎 InnoDB与Myisam的主要区别
  2. javascript数据结构与算法---栈
  3. &lt;Interview Problem&gt;二叉树根到叶节点求和值匹配
  4. C. Dima and Salad 背包好题
  5. hdu.1044.Collect More Jewels(bfs + 状态压缩)
  6. Tomcat 服务器性能优化
  7. C++——将成员函数作为参数
  8. GITHUB基础使用教程
  9. MVC开发 好的扩展套件(Visual Studio 插件)
  10. 获取文件路径 分类: WinForm 2014-07-25 14:27 103人阅读 评论(0) 收藏
  11. Storm流分组介绍
  12. 树莓派 wheezy安装与远程登录配置
  13. CSS中的浮动清除
  14. TypeScript入门知识二(参数新特性)
  15. winform自动更新程序实现
  16. non-ZenoAndAcceptingLocation
  17. SQL 三范式
  18. python:浅拷贝与深拷贝
  19. 定时器事件QtimerEvent 随机数 qrand Qtimer定时器
  20. ArrayList Vector LinkedList(一)

热门文章

  1. 富文本编辑器quill---vue组件(vue-quill-editor)的使用
  2. d3 数据绑定
  3. 移动web端使用rem实现自适应原理
  4. Linux System Programming 学习笔记(三) 标准缓冲I/O
  5. Keep-Alive 长连接(转载)
  6. Laravel 5.1 关掉csrf验证
  7. LeetCode OJ--Binary Tree Level Order Traversal
  8. Spring Tool Suite(STS)安装
  9. HDU 4912 Paths on the tree(LCA+贪心)
  10. linux grep 查找文件内容