How to package native commandline application in a

2019-01-04 03:14发布

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.

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

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

2条回答
在下西门庆
2楼-- · 2019-01-04 03:26

See Android NDK build with ANT script.

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.

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

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.

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.

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.

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

查看更多
对你真心纯属浪费
3楼-- · 2019-01-04 03:44

In general, you should put your commandline app into Assets folder, then use AssetManager in order to extract your asset (do not forget to chmod it after extraction!). But there will be a problem where to extract it to, because not every directory in Android may store executable binaries. On Android 2.2 I've tried /cache and it works. Cann't say for newer Androids. Sorry, can give no recommendations regarding ant.

查看更多
登录 后发表回答