How to include a binary file with Android NDK project?

断了今生、忘了曾经 提交于 2021-01-24 08:49:41

问题


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.

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


回答1:


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.

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

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, $<, $@)


来源:https://stackoverflow.com/questions/22967841/how-to-include-a-binary-file-with-android-ndk-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!