将 Android apk 与其他可执行文件一起打包
作为先前问题的后续(Android ioctl - root 权限和使用),是否可以创建一个单独的本机可执行文件并将其打包在 APK 中?
该应用程序需要 root 访问权限,并且不会进入 Android 市场,但我希望能够在不使用将额外可执行文件推送到设备上的脚本的情况下安装它。
As a follow up to an earlier question (Android ioctl - root permissions and usage), is it possible to create a separate native executable and package it in an APK?
The app needs root access and isn't going into the Android marketplace, but I'd like to be able to install it without using a script that pushes an extra executable onto the device.
有一种简单的方法可以将可执行文件打包到 APK 中,并让系统安装程序负责解压此可执行文件,请参阅 如何将原生命令行应用程序打包到apk中?。
技巧(测试到 Jelly Bean 4.3)是将文件命名为“libmyexecutable.so”并将其放入
libs/armeabi
中你的 Android 项目(我假设是 ADT 或 ant 构建)。包管理器会将文件解压到/data/data/your.package.full.name/lib
(这是一个符号链接,出于向后兼容性的原因,所以也许在 Android 的未来版本中这会不再工作)在设备上,具有可执行权限。请注意,该文件具有
all
读取和执行权限,因此您可以使用 Runtime.getRuntime().exec() 或 system() 也来自其他应用程序。更新:
如今,您应该对 32 位 ARM 可执行文件使用 libs/armeabi-v7a,并且您可能还需要准备相同可执行文件的 64 位 ARM 版本。
There is an easy way to package an executable into an APK, and let the system installer take care of unpacking this executable, see How to package native commandline application in apk?.
The trick (tested up to Jelly Bean 4.3) is to name the file "libmyexecutable.so" and put it into
libs/armeabi
of your Android project (I assume an ADT or ant build). The Package Manager will unpack the file to/data/data/your.package.full.name/lib
(it's a symbolic link, for backwards compatibility reasons, so maybe in some future version of Android this will not work anymore) on the device, with executable permissions.Note that the file has
all
read-and-execute permissions, so you can use Runtime.getRuntime().exec() or system() from other apps, too.Update:
These days, you should use
libs/armeabi-v7a
for 32 -bit ARM executables, and you probably need to prepare 64-bit ARM version of the same executables, too.