Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Packaging linux binary in Android apk

If I want to include a linux binary (like ffmpeg) in my .apk file (only for ARM based devices), is this possible to distribute for non rooted phones? I know it's possible to call an included binary with Runtime.exec() but is it a recommended practice?

like image 376
StackOverflowed Avatar asked Oct 17 '25 14:10

StackOverflowed


2 Answers

You can store the binary in res/raw or in assets folder. This way it will be deployed on the device. You should "extract" it after the installation, your /data/data/your.package/files/ is a valid destination; /sdcard/ is not. The usual /data/local/ destination is not accessible for your app, even if it is for an adb shell. chmod 500 is also fine.

This said, libffmpeg.so with JNI wrappers is easier to use in an Android app, and takes less system resources.


Update, Aprl 2014 You can trick the system, and store your binary in libs/armeabi folder, and let the installer extract this binary for you. It will end up in /data/data/your.package/lib/ folder, with +x permissions. This hack has another nice advantage, it lets the system choose the correct ABI to extract the binary for: armeabi, armeabi-v7a, mips, or x86.

The trick is to follow the shared library naming convention. So, when you put ffmpeg executable into libs/armeabi, rename the file to lib_ffmpeg_.so. Naturally, you will also Runtime.exec() the file using the full path, and the newly added prefix and suffix.

like image 164
Alex Cohn Avatar answered Oct 20 '25 02:10

Alex Cohn


I don't think you'll be able to get them marked as +x without root.

With ffmpeg, it's more usual to create a JNI wrapper for libffmpeg.

like image 1
alex Avatar answered Oct 20 '25 04:10

alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!