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?
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.
-
2It's reasonably common to launch native executables from Android apps, but you should be aware that it's frowned upon by the Android architects. They keep making threats to disable that facility in future, as they're unable to regulate the resource usage of those processes as precisely as they do for the main app process. – Adrian Taylor Feb 26 '13 at 22:06
-
Thank you @AlexCohn. Do you know of an FFMPEG JNI wrapper that utilizes a recent version of FFMPEG? (Preferably 2.0 onwards?). – StackOverflowed Apr 4 '14 at 23:09
-
@StackOverflowed: no, I don't track the dozens of ffmpeg wrappers and derivatives. – Alex Cohn Apr 5 '14 at 9:35
-
1@JonesV yes, it is. I have not tested this on Android Pie devices, but there is no documented change that could break this feature. One warning: unfortunately, this won't work with android:extractNativeLibs=false. – Alex Cohn Jan 21 '19 at 11:21
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.
-
This project seems to be able to do it, which is why I raised the question: github.com/guardianproject/android-ffmpeg – StackOverflowed Feb 26 '13 at 18:57