1. Linux环境模拟,下载sygwin 安装,选择devl 和shell -> install
sygwin 中的配置ndk环境,进入安装目录c:/cygwin64

etc/profile文件配置ndk的环境
//37行
  PATH="/usr/local/bin:/usr/bin:/cygdrive/d/android-ndk-r9d-windows-x86_64/android-ndk-r9d${PATH:+:${PATH}}"

2. 下载ndk

3. 开发,参考于ndk/sample/HelloJni
创建android 工程在JNTTest,在jni中创建3个文件

3.1 helo-jni.c中内容如下
/*
 * 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.
 *
 */
#include <string.h>
#include <jni.h>

/* This is a trivial JNI example where we use a native method
 * to return a new VM String. See the corresponding Java source
 * file located at:
 *
 *   apps/samples/hello-jni/project/src/com/example/hellojni/HelloJni.java
 */
jstring
Java_com_jun_jnitest_MainActivity_stringFromJNI( JNIEnv* env, jobject thiz )
{

 return (*env)->NewStringUTF(env, "Hello from JNI !  Compiled with ABI ");

}

3.2 Application.mk 内容如下:
APP_ABI := all

3.3 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    := hello-jni
LOCAL_SRC_FILES := hello-jni.c
include $(BUILD_SHARED_LIBRARY)

3.4 java文件编辑
package com.jun.jnitest;
public class MainActivity extends Activity {
   
public native String  stringFromJNI();

   /* This is another native method declaration that is *not*
    * implemented by 'hello-jni'. This is simply to show that
    * you can declare as many native methods in your Java code
    * as you want, their implementation is searched in the
    * currently loaded native libraries only the first time
    * you call them.
    *
    * Trying to call this function will result in a
    * java.lang.UnsatisfiedLinkError exception !
    */
   public native String  unimplementedStringFromJNI();
 
//  静态代码块,先于构造函数执行,在此会对C/C++代码的库即:*.so文件进行加载
  static {
        //hello-jni 为在android.mk 中定义的名称
      System.loadLibrary("hello-jni");
    }
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// System.out.println(stringFromJNI());
}

public void click(View view) {
                    //使用
Toast.makeText(this, stringFromJNI(), 0).show();
}
 

}


3.5 利用cygwin编译
cd 到当前android 工程目录下 /cygdrive/d/android/workspace/jnitest
Luv@Luv-PC /cygdrive/d/android/workspace/jnitest
$ ndk-build
Android NDK: WARNING: APP_PLATFORM android-19 is larger than android:minSdkVersion 8 in ./AndroidManifest.xml
[armeabi-v7a] Compile thumb  : hello-jni <= hello-jni.c
[armeabi-v7a] SharedLibrary  : libhello-jni.so
[armeabi-v7a] Install        : libhello-jni.so => libs/armeabi-v7a/libhello-jni.so
[armeabi] Compile thumb  : hello-jni <= hello-jni.c
[armeabi] SharedLibrary  : libhello-jni.so
[armeabi] Install        : libhello-jni.so => libs/armeabi/libhello-jni.so
[x86] Compile        : hello-jni <= hello-jni.c
[x86] SharedLibrary  : libhello-jni.so
[x86] Install        : libhello-jni.so => libs/x86/libhello-jni.so
[mips] Compile        : hello-jni <= hello-jni.c
[mips] SharedLibrary  : libhello-jni.so
[mips] Install        : libhello-jni.so => libs/mips/libhello-jni.so

3.6 运行

jni ndk 入门的更多相关文章

  1. Android Studio JNI开发入门教程

    Android Studio JNI开发入门教程 2016-08-29 14:38 3269人阅读 评论(0) 收藏 举报  分类: JNI(3)    目录(?)[+]   概述 在Andorid ...

  2. Android NDK 入门与实践

    NDK 是什么 NDK 全称 Native Development Kit,可以让您在 Android 应用中调用 C 或 C++ 代码的工具. NDK 好处 1.NDK 可以生成 .so 文件, 方 ...

  3. 将 so|JNI|NDK 之间的关系说明白

    最近在了解公司历史的发展,发现了公司产品中几乎都要使用 so 文件,不禁好奇这个 so 到底是何方神圣. so 文件 so 是 shared object 的缩写,见名思义就是共享的对象,机器可以直接 ...

  4. JNI/NDK开发指南(开山篇)

    转载请注明出处:http://blog.csdn.net/xyang81/article/details/41759643 相信很多做过Java或Android开发的朋友经常会接触到JNI方面的技术, ...

  5. JNI NDK (AndroidStudio+CMake )实现C C++调用Java代码流程

    JNI/NDK Java调用C/C++前言  通过第三篇文章讲解在实际的开发过程中Java层调用C/C++层的处理流程.其实我们在很大的业务里也需要C/C+ +层去调用Java层,这两层之间的相互调用 ...

  6. (转)java 层调用Jni(Ndk) 持久化c c++ 对象

    对于Jni(Ndk) 很多人应该都有印象,Android的ndk接触到的机会相对会比较多,本例子以android平台为例,pc端的话就以简单的windows为例, 编码完用vs 或是 gcc进行编译成 ...

  7. android Jni NDK开发环境搭建及其简单实例的编写

    android  Jni  NDK开发环境搭建及其简单实例的编写 由于工作需要,需要采用开发想要的JNI,由于之前没有接触过安卓的开发,所以更加网上的帖子,学习了下.遇到了些问题,然后总结下学习过程中 ...

  8. Android M中 JNI的入门学习

    今年谷歌推出了Android 6.0,作为安卓开发人员,对其学习掌握肯定是必不可少的,今天小编和大家分享的就是Android 6.0中的 JNI相关知识,这是在一个安卓教程网上看到的内容,感觉很不错, ...

  9. Android JNI/NDK开发教程

    JNI/NDK开发指南:http://blog.csdn.net/xyang81/article/details/41759643

随机推荐

  1. mysql创建用户及授权

    创建本地账号 create user 'egon1'@'localhost' identified by '123'; # mysql -uegon1 -p123 创建远程账号 create user ...

  2. 【Linux学习】Linux文件系统2—linux常用目录结构、绝对路径、相对路径

    Linux文件系统2-linux常用目录结构.绝对路径.相对路径 一. 常见目录结构总结 Linux目录结构就是"树形结构",常见的目录结构: /bin  系统需要的命令位于此目录 ...

  3. Win7 server2008 共享文件夹 不输入网络密码

    如何设置共享文件夹访问不需要输入用户名和密码: 1.“开始”——“运行”——secpol.msc (1)使用空白密码的本地帐户只允许进行控制台登录 禁用它 (2)“本地策略”——“安全选项”——“网络 ...

  4. C#简单的国际化

    1.新建一个资源文件夹,并在资源文件夹新建中英问的资源文件,如图: 2.中英文资源文档添加资源,如图: 3.Program.cs中添加根据系统语言确定中英文,这里默认为英文: using Intern ...

  5. Unity的http通信--unity与python的django通信

    http://blog.csdn.net/chenggong2dm/article/details/17372203 写在前面: WWW类,是unity里,简单的访问网页的类.本文介绍的就是这种方式, ...

  6. jzoj5991. 【北大2019冬令营模拟2019.1.6】Juice

    题面 题解 好迷-- //minamoto #include<bits/stdc++.h> #define R register #define ll long long #define ...

  7. vant搜索框问题

    最近使用vant搜索框时发现,当输入内容点击一次搜索有数据,点击错号把内容去掉再点击搜索,都没进入点击搜索方法. 解决方法:把bindtop改成bindtouchstart <van-searc ...

  8. UITableView以及cell属性

    在ios的UI中UITableView是个常用且强大的控件 基本使用: 1>设置代理,一般把控制器设为代理:self.tableView.delegate = self; 2>遵守代理的协 ...

  9. github 收藏项目的方法

    1,Watching 需要收藏的项目 2,查看收藏的项目

  10. python 对mongdb的简单操作

    准备工作:1.选择安装合适的mongodb到本地电脑,2.创建mongodb实例,3,开启mongodb实例,4,下载pymongo第三方库,5.下载pycharm对mongodb可视化支持的插件mo ...