Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package Android apk with additional executables

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.

like image 732
derekerdmann Avatar asked Aug 09 '11 15:08

derekerdmann


People also ask

Is an APK file an executable?

A file with . apk extension is a Google Android app file that is used to install apps (applications) on the Android devices. It is created as an executable file using the official IDE Google Android Studio, and is uploaded to Google Play store to be downloaded and installed by end users.

What is difference between APK and AAB?

AABs can be used to make apps smaller (apps using AABs on Google Play are 15% smaller on average versus a universal APK), which means faster installs for users and more installs for developers. AABs reduce release complexity and save developers time.

What do android package .APK files contain?

An APK (Android Package Kit) is the file format for applications used on the Android operating system. APK files are compiled with Android Studio, which is the official integrated development environment (IDE) for building Android software. An APK file includes all of the software program's code and assets.

What is the difference between EXE and APK?

The difference is very basic .exe is a windows installation package and and . apk is a not so safe method of installing android apps. . apks are very safe or a very unsafe depending on who you download it from.


2 Answers

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.

like image 90
Alex Cohn Avatar answered Oct 14 '22 23:10

Alex Cohn


You can put it into assets and copy it to the app's private directory on first run. After you set the executable bit, you should be able to run it.

like image 41
Nikolay Elenkov Avatar answered Oct 15 '22 00:10

Nikolay Elenkov