在Android apk中打包linux二进制文件 [英] Packaging linux binary in Android apk

查看:384
本文介绍了在Android apk中打包linux二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想在我的.apk文件(仅适用于基于ARM的设备)中包含一个linux二进制文件(如ffmpeg),是否可以为非root手机分发?我知道有可能使用Runtime.exec()调用一个包含的二进制文件,但它是推荐的做法吗?

解决方案

您可以在 res / raw 资产文件夹。这样它将部署在设备上。您应该在安装后提取,您的 /data/data/your.package/files / 是有效的目的地; / sdcard / 不是。通常的 / data / local / 目标位置无法访问您的应用程序,即使它是用于adb shell。

这就是说,libffmpeg.so与JNI包装器在Android中更容易使用应用程序,并且需要较少的系统资源。






更新,2014年4月您可以欺骗系统,并将您的二进制文件存储在 libs / armeabi 文件夹中,然后让安装程序为您解压缩此二进制文件。它将以 /data/data/your.package/lib / 文件夹结尾,其中包含 + x 权限。这个黑客有另一个很好的优势,它允许系统选择正确的ABI来提取二进制文件: armeabi armeabi-v7a mips x86



诀窍是遵循共享库命名约定。因此,当您将 ffmpeg 可执行文件放入 libs / armeabi 中时,将文件重命名为 lib_ffmpeg_.so 。当然,您也将使用完整路径的 Runtime.exec(),以及新添加的前缀和后缀。


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.

这篇关于在Android apk中打包linux二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆