| |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
-> 系统运维 -> Android NDK 开发编译简要说明 -> 正文阅读 |
|
[系统运维]Android NDK 开发编译简要说明 |
概述? 在android NDK中开发jni, 可下的c和cpp等文件, 得到.so文件. 编译环境配置下载NDK:??https://developer.android.com/ndk/guides? ?上面有使用说明,有时间可仔细阅读. 下载ndk后, 不需要安装, 解压到本地某个目录,配置环境变量: Ubuntu环境配置: 1. 配置NDK环境变量, 执行如下命令: sudo gedit /etc/profile 说明:?打开全局环境变量文件,添加NDK的环境变量,就额可以在任意地方使用ndk-build命令了. #set android ndk env 说明: 我目前使用的还是android-ndk-r15c, 最新版本已经23了,但是ndk里面结构已经变化了,好像会有问题,还没有研究怎么用. 2. 使环境变量立刻生效, 执行如下命令: source?/etc/profile 3. ceshi NDK是否配置完成: XXXXX-contacts155$ ndk-build -h 就这样, NDK开发环境就配置好了,开始使用. 举例说明如下图; 手动编译jni目录 jni最重要说明:? 1. 模块根目录下,新建jni目录,?里面新建两个必不可少的编译文件?Android.mk 和?Application.mk (1) Application.mk:
(2) Android.mk ?
2. 直接在jni目录下编写c和c++文件, 此处省略了, 看官们自己脑补. 大概是这样:
?3. 编译 执行如下命令: ndk-build -C ./jni 只要不出现错误,就能看到编译出来的so文件了, 直接看下面的例子: hulk@hulk-PC:~/byod/code/byod_new3/Byod-contacts155$ ndk-build -C ./jni Android NDK: APP_PLATFORM set to unknown platform: android-25. ? ? make: Entering directory `/home/hulk/byod/code/hulk-jni/jni' /home/hulk/tools/android-ndk-r15c/build/core/setup-app-platform.mk:115: *** Android NDK: Aborting ? ?. ?Stop. make: Leaving directory `/home/hulk/byod/code/hulk-jni/jni' hulk@hulk-PC:~/byod/code/byod_new3/Byod-contacts155$ ndk-build -C ./jni Android NDK: WARNING: APP_PLATFORM android-26 is higher than android:minSdkVersion 1 in /home/hulk/byod/code/hulk-jni/AndroidManifest.xml. NDK binaries will *not* be comptible with devices older than android-26. See https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md for more information. ? ? make: Entering directory `/home/hulk/byod/code/hulk-jni/jni' [armeabi] Compile thumb ?: hulk-jni <= centraldir.c [armeabi] Compile++ thumb: hulk-jni <= com_hulk_contacts_support_NativeManager.cpp In file included from /home/hulk/byod/code/hulk-jni/jni/com_hulk_contacts_support_NativeManager.cpp:23: /home/hulk/byod/code/hulk-jni/jni/quickfinder.h:32:20: warning: 'getDuoyinzi' has C-linkage specified, but returns incomplete type 'const list<std::string>' (aka 'const ? ? ? list<basic_string<char, char_traits<char>, allocator<char> > >') which could be incompatible with C [-Wreturn-type-c-linkage] const list<string> getDuoyinzi(int unicode); ? ? ? ? ? ? ? ? ? ?^ 1 warning generated. [armeabi] Compile++ thumb: hulk-jni <= BinPatch.cpp [armeabi] Compile++ thumb: hulk-jni <= BinaryPatch.cpp [armeabi] Compile++ thumb: hulk-jni <= quickfinder.cpp In file included from /home/hulk/byod/code/hulk-jni/jni/quickfinder.cpp:6: /home/hulk/byod/code/hulk-jni/jni/quickfinder.h:32:20: warning: 'getDuoyinzi' has C-linkage specified, but returns incomplete type 'const list<std::string>' (aka 'const ? ? ? list<basic_string<char, char_traits<char>, allocator<char> > >') which could be incompatible with C [-Wreturn-type-c-linkage] const list<string> getDuoyinzi(int unicode); ? ? ? ? ? ? ? ? ? ?^ 1 warning generated. [armeabi] Compile++ thumb: hulk-jni <= telutil.cpp [armeabi] SharedLibrary ?: libhulk-jni.so [armeabi] Install ? ? ? ?: libhulk-jni.so => libs/armeabi/libhulk-jni.so [armeabi-v7a] Compile thumb ?: hulk-jni <= centraldir.c [armeabi-v7a] Compile++ thumb: hulk-jni <= com_hulk_contacts_support_NativeManager.cpp In file included from /home/hulk/byod/code/hulk-jni/jni/com_hulk_contacts_support_NativeManager.cpp:23: /home/hulk/byod/code/hulk-jni/jni/quickfinder.h:32:20: warning: 'getDuoyinzi' has C-linkage specified, but returns incomplete type 'const list<std::string>' (aka 'const ? ? ? list<basic_string<char, char_traits<char>, allocator<char> > >') which could be incompatible with C [-Wreturn-type-c-linkage] const list<string> getDuoyinzi(int unicode); ? ? ? ? ? ? ? ? ? ?^ 1 warning generated. [armeabi-v7a] Compile++ thumb: hulk-jni <= BinPatch.cpp [armeabi-v7a] Compile++ thumb: hulk-jni <= BinaryPatch.cpp [armeabi-v7a] Compile++ thumb: hulk-jni <= quickfinder.cpp In file included from /home/hulk/byod/code/hulk-jni/jni/quickfinder.cpp:6: /home/hulk/byod/code/hulk-jni/jni/quickfinder.h:32:20: warning: 'getDuoyinzi' has C-linkage specified, but returns incomplete type 'const list<std::string>' (aka 'const ? ? ? list<basic_string<char, char_traits<char>, allocator<char> > >') which could be incompatible with C [-Wreturn-type-c-linkage] const list<string> getDuoyinzi(int unicode); ? ? ? ? ? ? ? ? ? ?^ 1 warning generated. [armeabi-v7a] Compile++ thumb: hulk-jni <= telutil.cpp [armeabi-v7a] SharedLibrary ?: libhulk-jni.so [armeabi-v7a] Install ? ? ? ?: libhulk-jni.so => libs/armeabi-v7a/libhulk-jni.so [x86] Compile ? ? ? ?: hulk-jni <= centraldir.c [x86] Compile++ ? ? ?: hulk-jni <= com_hulk_contacts_support_NativeManager.cpp In file included from /home/hulk/byod/code/hulk-jni/jni/com_hulk_contacts_support_NativeManager.cpp:23: /home/hulk/byod/code/hulk-jni/jni/quickfinder.h:32:20: warning: 'getDuoyinzi' has C-linkage specified, but returns incomplete type 'const list<std::string>' (aka 'const ? ? ? list<basic_string<char, char_traits<char>, allocator<char> > >') which could be incompatible with C [-Wreturn-type-c-linkage] const list<string> getDuoyinzi(int unicode); ? ? ? ? ? ? ? ? ? ?^ 1 warning generated. [x86] Compile++ ? ? ?: hulk-jni <= BinPatch.cpp [x86] Compile++ ? ? ?: hulk-jni <= BinaryPatch.cpp [x86] Compile++ ? ? ?: hulk-jni <= quickfinder.cpp In file included from /home/hulk/byod/code/hulk-jni/jni/quickfinder.cpp:6: /home/hulk/byod/code/hulk-jni/jni/quickfinder.h:32:20: warning: 'getDuoyinzi' has C-linkage specified, but returns incomplete type 'const list<std::string>' (aka 'const ? ? ? list<basic_string<char, char_traits<char>, allocator<char> > >') which could be incompatible with C [-Wreturn-type-c-linkage] const list<string> getDuoyinzi(int unicode); ? ? ? ? ? ? ? ? ? ?^ 1 warning generated. [x86] Compile++ ? ? ?: hulk-jni <= telutil.cpp [x86] SharedLibrary ?: libhulk-jni.so [x86] Install ? ? ? ?: libhulk-jni.so => libs/x86/libhulk-jni.so make: Leaving directory `/home/hulk/byod/code/hulk-jni/jni' hulk@hulk-PC:~/byod/code/byod_new3/Byod-contacts155$ 至此,.so文件就饿生成在与jni同级别沐浴露的libs目录下了:? libs/armeabi/libhulk-jni.so libs/armeabi-v7a/libhulk-jni.so libs/x86/libhulk-jni.so 总结Android jni开发三要点 1. 下载NDK,配置环境变量 2. 新建jni目录.仙剑Android.mk 和 Application.mk 3. 编辑c和c++文件 4. 编译:?ndk-build -C ./jni |
|
|
上一篇文章 下一篇文章 查看所有文章 |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 | -2024/11/15 15:00:00- |
|
网站联系: qq:121756557 email:121756557@qq.com IT数码 |