Packaging linux binary in Android apk

前端 未结 2 1226
粉色の甜心
粉色の甜心 2020-12-19 20:02

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 t

2条回答
  •  爱一瞬间的悲伤
    2020-12-19 20:34

    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.

提交回复
热议问题