如何在Android NDK项目中包含二进制文件? [英] How to include a binary file with Android NDK project?

查看:118
本文介绍了如何在Android NDK项目中包含二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道它的不好做法,但是在Android NDK项目中包含二进制文件的最佳方法是什么?该文件应使用系统命令可执行.

I know its bad practice but whats the best way to include a binary file with Android NDK project? The file should be executable with the system command.

我不想手动将其复制到设备上,而是将其分发到我的.apk中.

I don't want to copy it manually copy to the device but distribute it within my .apk.

推荐答案

将可执行文件重命名为"lib_myexecutable_.so"并将其放在项目根目录下的libs/armeabi文件夹中就足够了:程序包管理器将提取此文件.在设备上使用/data/data/your.package.full.name/lib并具有可执行权限.

It is enough to rename the executable to "lib_myexecutable_.so" and put it in libs/armeabi folder under your project root: this file will be extracted by the Package Manager on the device to /data/data/your.package.full.name/lib, with executable permissions.

如果使用ndk-build来构建myexecutable,则所有./libs/$(TARGET_ARCH_ABI)目录都将被刷新.

If you use ndk-build to build myexecutable, all ./libs/$(TARGET_ARCH_ABI) directory will be refreshed.

要自动执行重命名操作,请在Android.mk中使用以下命令:

To automate the rename operation, use the following in your Android.mk:

... # whatever you have to define the executable
include $(BUILD_EXECUTABLE)
# immediately after this,
all: .libs/$(TARGET_ARCH_ABI)/lib_myexecutable_.so

.libs/$(TARGET_ARCH_ABI)/lib_myexecutable_.so: $(LOCAL_INSTALLED)
<tab>$(call host-mv, $<, $@)

这篇关于如何在Android NDK项目中包含二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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