4

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?

asked Feb 26, 2013 at 16:01

2 Answers 2

10

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.

answered Feb 26, 2013 at 21:30
Sign up to request clarification or add additional context in comments.

4 Comments

It'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.
Thank you @AlexCohn. Do you know of an FFMPEG JNI wrapper that utilizes a recent version of FFMPEG? (Preferably 2.0 onwards?).
@StackOverflowed: no, I don't track the dozens of ffmpeg wrappers and derivatives.
@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.
1

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.

answered Feb 26, 2013 at 16:05

1 Comment

This project seems to be able to do it, which is why I raised the question: github.com/guardianproject/android-ffmpeg

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.