NDK

Android:JNI 与 NDK到底是什么?(含实例教学)

[亡魂溺海] 提交于 2019-12-06 08:28:46
前言 在 Android 开发中,使用 NDK 开发的需求正逐渐增大 但很多人却搞不懂 JNI 与 NDK 到底是怎么回事 今天,我将先介绍 JNI 与 NDK & 之间的区别,手把手进行 NDK 的使用教学,希望你们会喜欢 目录 1. JNI介绍 1.1 简介 定义: Java Native Interface ,即 Java 本地接口 作用: 使得 Java 与 本地其他类型语言(如 C、C++ )交互 即在 Java 代码 里调用 C、C++ 等语言的代码 或 C、C++ 代码调用 Java 代码 特别注意: JNI 是 Java 调用 Native 语言的一种特性 JNI 是属于 Java 的,与 Android 无直接关系 1.2 为什么要有 JNI 背景:实际使用中, Java 需要与 本地代码 进行交互 问题:因为 Java 具备 跨平台 的特点,所以 Java 与 本地代码交互的能力非常弱 解决方案: 采用 JNI 特性 增强 Java 与 本地代码交互的能力 1.3 实现步骤 在 Java 中声明 Native 方法(即需要调用的本地方法) 编译上述 Java 源文件javac(得到 .class 文件) 通过 javah 命令导出 JNI 的头文件( .h 文件) 使用 Java 需要交互的本地代码 实现在 Java 中声明的 Native 方法 如 Java

学习:APP_ABI

痴心易碎 提交于 2019-12-06 07:55:32
在Application.mk文件中有个预定义命令参数APP_ABI,是指明编译与调试的CPU架构。 目前Android系统支持以下七种不同的CPU架构:ARMv5,ARMv7(从2010年起),x86(从2011年),MIPS(从2012年),ARMv8,MIPS64和x86_64(从2014年),每一种都对应相应的ABI。 CPU架构 ABI ARMv5 armeabi 32位,从2010年 ARMv7 armeabi-v7a 32位,从2010年 x86 x86 32位,从2011年 MIPS mips 32位,从2012年 ARMv8 arm64-v8a 64位,从2014年 MIPS64 mips64 64位,从2014年 x86_64 x86_64 64位,从2014年 相应生成arm64-v8a,mips64,x86_64下的文件需要NDK_r10以上版本支持。在Application.mk文件里配置APP_ABI的内容。例如指明某个具体的CPU架构 APP_ABI := arm64-v8a 或者直接生成所有的版本 APP_ABI := all 注意: 根据不同的NDK版本,APP_ABI := all仅能生成当前版本支持的ABI信息库文件,如果需要生成最新的必须更新相应的NDK版本。 或者明确写明支持的CPU架构 APP_ABI := armeabi,armeabi

Android NDK开发

五迷三道 提交于 2019-12-06 07:55:04
##编译问题## 1、eclipse编译错误,提示“clang++.exe: error: invalid linker name in argument '-fuse-ld=bfd'” 解决:将Android.mk文件中的“LOCAL_LDFLAGS += -fuse-ld=bfd”修改为“LOCAL_LDFLAGS += -fuse-ld=bfd.exe” ##平台架构## Android系统目前支持以下七种不同的CPU架构:ARMv5,ARMv7(从2010年起),x86(从2011年起),MIPS(从2012年起),ARMv8,MIPS64和x86_64(从2014年起),每一种都关联着一个相应的ABI。 每一个CPU架构对应一个ABI:armeabi,armeabi-v7a,x86,mips,arm64-v8a,mips64,x86_64。 ##Android如何加载.so文件## 不同CPU架构的Android手机加载时会在libs下找相对应的目录,并从对应的目录下寻找需要的.so文件; 如果没有对应的目录,就会去armeabi或者armeabi-v7a下去寻找,兼容运行; 如果有对应的目录,但是没有找到对应的.so文件,也不会去armeabi下去寻找,直接报错。 ##平台的兼容## armeabi架构 armeabi-v7a架构 v7a的CPU支持硬件浮点运算

Setting up Automatic NDK Builds in Eclipse

夙愿已清 提交于 2019-12-06 06:42:52
When editing native JNI code in an Android project using the Android NDK you may configure Eclipse to automatically rebuild your project when editing native code, just as it does for java. The below steps shows how to perform the necessary configuration (note that this requires revision 4 or later of the NDK - previous revisions does not contain the necessary ndk-build binary): Start by right clicking on your android project (named hello-neon in the below screenshots) with JNI resources, and select Properties . In the resulting dialog, choose the Builders entry in the list to the left and

How to Build ffmpeg with NDK r9

∥☆過路亽.° 提交于 2019-12-06 06:42:40
This is a updated post for a previous post, where we built ffmpeg 0.8 with Android NDK r5 and r6 . This post will give instructions of how to build ffmpeg 2.0.1 with Android NDK r9. Download Android NDK The latest version of Android NDK can be downloaded at Android NDK website . At the time of writing, the newest version is NDK r9. Note that the website provides both current and legacy toolchains. We only need the current toolchain to compile ffmpeg. After download NDK, simply decompress the archive. Note that we’ll use $NDK to represent the root path of the decompressed NDK. Download ffmpeg

Build ffmpeg with NDK r9(转载)

雨燕双飞 提交于 2019-12-06 06:42:30
How to Build ffmpeg with NDK r9 by ROMAN10 on AUGUST 18, 2013 · 52 COMMENTS This is a updated post for a previous post, where we built ffmpeg 0.8 with Android NDK r5 and r6 . This post will give instructions of how to build ffmpeg 2.0.1 with Android NDK r9. 0. Download Android NDK The latest version of Android NDK can be downloaded at Android NDK website . At the time of writing, the newest version is NDK r9. Note that the website provides both current and legacy toolchains. We only need the current toolchain to compile ffmpeg. After download NDK, simply decompress the archive. Note that we’ll

用 NDK编译Graphite2

对着背影说爱祢 提交于 2019-12-06 06:42:17
Graphite is a "smart font" system developed specifically to handle the complexities of lesser-known languages of the world. 上面这段话是从Graphite的官网( http://scripts.sil.org/cms/scripts/page.php?site_id=projects&item_id=graphite_hom )上摘的对于这个Open Source library的功能的描述。它是一个类似于Harfbuzz的一个文本shape的引擎,只不过,它在shape的过程中,会更加依赖于font文件中提供的信息。对于缅甸语的处理, Graphite引擎 + Padauk font 文件的组合方案,堪称完美。 这个library用到的API也大多在standard C++的范围之内,这就给用NDK编译这个library创造了很好的条件。 在NDK中使用STL的方法,可以看到Google官方文档(prebuilts/ndk/7/sources/cxx-stl/gnu-libstdc++/README)中的一段话: This directory contains the headers and prebuilt binaries for the GNU

Android.mk文件语法规范

泄露秘密 提交于 2019-12-06 06:42:03
序言: ————- 此文档旨在描述Android.mk文件的语法,Android.mk文件为Android NDK(原生开发)描述了你C/C++源文件。 为了明白下面的内容,你必须已经阅读了docs/OVERVIEW.TXT的内容,它解释了Android.mk文件扮演的角色 和用途。 概述: ——— 写一个Android.mk文件是为了向生成系统描述你的源代码。更明确的说: - 这个文件实际上是GNU Make文件的一小片段,它会被生成系统解析一次或多次。 因此,你应该在Android.mk里尽量少地声明变量,而不要误以为在解析的过程中 没有任何东西被定义。 - 该文件的语法的明的人为了让你能将你的源代码组织为组件(module).一个组件指的是下面的一项: - 一个静态库(static library) - 一个共享库(shared library) 只有一个动态库会被安装/拷贝至你的application package中。但是静态库可用来 生成动态库。 你可以在每个Android.mk文件定义一个或多个组件,并且我可以在几个组件中使用 相同的源文件。 - 生成系统为你处理了一些琐碎之事。比如,在你的Android.mk里,你不须要列出头文件或 列出生成的文件之间的明确认依赖关系。NDK生成系统会为你自动生成。 这也意味着,当更新至新的NDK版本时,你能得到新的工具链/平台支持

Android NDK

可紊 提交于 2019-12-06 01:58:20
{ Usage: make [options] [target] ... Options: -b, -m Ignored for compatibility. -B, --always-make Unconditionally make all targets. -C DIRECTORY, --directory=DIRECTORY Change to DIRECTORY before doing anything. -d Print lots of debugging information. --debug[=FLAGS] Print various types of debugging information. -e, --environment-overrides Environment variables override makefiles. -f FILE, --file=FILE, --makefile=FILE Read FILE as a makefile. -h, --help Print this message and exit. -i, --ignore-errors Ignore errors from commands. -I DIRECTORY, --include-dir=DIRECTORY Search DIRECTORY for

使用NDK构建android程序

感情迁移 提交于 2019-12-05 21:27:57
需要将Android sdk升级为4.0. 然后配置好sdk 在创建项目好的时候,右键 android tools->add native support->写入ndk名字。在ndk名字.cpp中写入函数 如下: extern "C" jstring Java_com_example_testandroid_MainActivity_stringFromJNI( JNIEnv* env, jobject thiz ) { return env->NewStringUTF((char *)"Hello from JNI !"); } extern "c"不能少,因为底层构建是按照c的语法来的。 Java 开头字母一定要大写. _com_example_testandroid为activity包名 _ MainActivity 要使用jni的activity类名。 stringfromJNI 此为函数名。 最后在activity中写入以下东西: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv = new TextView(this); tv.setText( stringFromJNI() );