如何在 apk 中打包原生命令行应用程序? [英] How to package native commandline application in apk?

查看:35
本文介绍了如何在 apk 中打包原生命令行应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个 Android 原生命令行应用程序打包成一个 apk.我有使用 jni/Android.mk 的 ndk-build 构建应用程序.输出在 libs/armeabi/ 中.我也有带蚂蚁的 apk 构建.但是,apk 似乎没有选择命令行应用程序.如果我解压缩 apk,应用程序不在那里.

I would like to package an Android native commandline application into an apk. I have the application building with ndk-build which uses jni/Android.mk. The output is in libs/armeabi/<MyApp>. I also have the apk building with ant. However, the apk does not seem to pick up the commandline application. If I unzip the apk the app is not in there.

我需要做什么才能让 ant 包含一个预先构建的命令行应用程序?

What do I need to do to get ant to include a pre-built commandline app?

另外,我需要做什么才能让 ant 运行 ndk-build?(这已经得到回答:Android NDK build with ANT script)

Also, what do I need to do so that ant runs ndk-build? (This was already answered: Android NDK build with ANT script)

推荐答案

参见 Android NDK使用 ANT 脚本构建.

如果 Ant 没有自动从 libs/armeabi 复制二进制文件,您可以使用 aapt 将二进制文件添加到 APK,请参阅 Ant 脚本中 aapt 元素的文档.

You can add the binary to APK using aapt if Ant does not copy it automatically from libs/armeabi, see Documentation for aapt element in Ant script.

我相信文件会被正确解压到/data/data/your.package.full.name/lib,具有可执行权限.

I believe that the file will be correctly extracted to /data/data/your.package.full.name/lib, with executable permissions.

Ant 构建涉及一个步骤,称为ApkBuilder",它只添加来自 libs/armeabi 的匹配模式 ^.+.so$ 的文件或 gdbserver - 后者仅用于调试构建.

Ant build involves a step called "ApkBuilder", which only adds files from libs/armeabi that match pattern ^.+.so$ or gdbserver - the latter for debug build only.

但是将可执行文件重命名为 "myexecutable.so" 是不够的:设备上的 APK 安装程序不会提取此文件.

But it is not enough to rename the executable to "myexecutable.so": this file will not be extracted by the APK installer on the device.

将可执行文件重命名为 "libmyexecutable.so" 就足够了:APK 将提取此文件安装程序 设备上的包管理器到/data/data/your.package.full.name/lib,具有可执行权限.

It is enough to rename the executable to "libmyexecutable.so": this file will be extracted by the APK installer Package Manager on the device to /data/data/your.package.full.name/lib, with executable permissions.

我个人喜欢给这个实际上不是图书馆的图书馆取一个特殊的名字,例如lib...ffmpeg...so.

I personally like to give this not-actually-a-library some special name, e.g. lib...ffmpeg...so.

UPDATE 6 年和 12 个 API 级别之后,这种方法仍然有效.但是对于 Android App Bundle,包管理器的默认行为不是从 APK 中提取本机库,而是就地使用它们.此处以及对此答案的评论中,您会找到一些解决方法.特别吸引人的是将可执行文件称为"/path/to/MyApp.apk!lib...ffmpeg...so",但我没有测试 此符号不适用于 System.exec().有关讨论,请参阅 IssueTracker.

UPDATE 6 years and 12 API levels later, this approach is still valid. But with Android App Bundle, the default behavior of the package manager is not to extract the native libraries from the APK, using them in-place. Here and in comments to this answer, you will find some workarounds for that. The one that is especially attractive, is to refer to the executable as "/path/to/MyApp.apk!lib...ffmpeg...so", but I have not tested this notation does not work with System.exec(). See IssueTracker for discussion.

请注意,现在有一个特殊的例外>wrap.sh.

Note that now there is a special exception for wrap.sh.

这篇关于如何在 apk 中打包原生命令行应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆