How to include a binary file with Android NDK project?

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.

Answers


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

Need Your Help

No package 'mono' found when installing XSP

linux nginx mono centos xsp

I am trying to get Mono working on nginx with fastCGI.

Could not find gradle 2.2.0-rc1

android android-studio android-gradle gradle-plugin

After updating to Android Studio 2.2 RC, it asked me to update gradle plugin to 2.2.0-rc1. When I update I get the following error: