Updated 02-Mar-2013 : Installing as user app instead of system app [ jump to this ]

If you are one of those who constantly keep switching between custom ROM’s and do not feel the need to pay for apps like Titanium Backup to backup all the android apps you currently have installed on your phone, then this is the article for you. I will show you how to easily create a custom android apps zip file that can be flashed in one go via the CWM(ClockWorkMod) recovery. These apps are upgradable after you flash them.

There is already a free android app available called “App2Zip” which will allow you to do exactly the same thing via a GUI, but if you are thinking, how hard can it be to create a zip file containing your favorite apps, then you are right. It is not hard at all, as I shall now demonstrate.

First, you will need a skeleton zip file, which contains the META-INF folder. This folder basically contains an updater-script which will mount the system partition and copy your apps into it. Go ahead and download this skeleton zip file from here.

Now, copy the zip file to a convenient location and unzip it.

$ mkdir -p ~/custom_apps
$ cp sample.zip ~/custom_apps
$ cd ~/custom_apps
$ unzip sample.zip
$ rm sample.zip

At this point, you should see two folders META-INF/ and system/. The system folder follows exactly the same directory structure as the system/ partition on your android device. The META-INF/ folder as mentioned before, contains the updater-script which mounts the system/ partition of your phone and copies your apps into it. If you use ADB(Android Debug Bridge), you can view the contents of the system/ partition on your android device using the command below.

$ adb shell ls /system/

If you are unfamiliar with ADB, you can start by reading through one of my previous blog post on adb and some of the cool stuff you can do with it.

Of all the directories in the system/ partition, we will concentrate on the app/ and the media/ directories in this article.

As you might have guessed, the app folder is where your android apps(your system apps, to be exact) go, and the media/ folder is where you will find ringtones, alarms and notifications.

So, how do you get the android apps from your android device ?

$ mkdir ~/my_android_apps
$ adb pull /data/app/ ~/my_android_apps/

All the android apps(.apk files) that you had installed on your android device will now be available in the my_android_apps/ folder. Basically, all user apps are stored in /data/app/ and all system apps are stored in /system/app on your phone. Some other apps might have been installed at some other location. You might want to enter the following command to find all the .apk files on your device and copy the required ones to the my_android_apps/ folder before we begin creating the zip file. Be sure to start ADB as root before you enter the following command.

$ adb shell find / -name "*.apk"

You can use “adb pull” on the path names returned by the find command above to copy the apk files corresponding to the apps you want to backup. Once, the folder my_android_apps/ has all the android apps(.apk files) you need, you are ready to start creating your custom flash-able zip file.

$ cd ~/custom_apps/
$ mkdir -p system/app
$ mkdir -p system/media/audio/ringtones
$ mkdir -p system/media/audio/notifications
$ mkdir -p system/media/audio/alarms

You now have created a system/ folder that mimics the directory structure of the system/ partition of your android device. Now, copy all the apps from my_android_apps/ folder to the system/app/ folder.

$ cp ~/my_android_apps/* ~/custom_apps/system/app/

Similarly, you can also put any ringtones, notifications and alarms(.ogg files) into the corresponding directories you just created above. You can also put any boot-animation zip file into the custom_apps/system/ directory(make sure you rename the boot-animation zip file to whatever name was already present for the boot-animation on your android device). You may also put and new fonts into the custom_apps/system/fonts/ directory after creating one. Now, you are ready to create the zip file.

$ 7z a my_android_apps.zip ~/custom_apps/*

Thats it!!!. You now have a zip file of your favorite android apps and media which can be flashed at the CWM recovery just like you flash gapps or any custom ROM. Note that I have used the 7zip utility to create the zip file. You may have to install it first on your Linux box before you run the above command. On Ubuntu, you can install it as:

$ sudo apt-get install p7zip-full

Now, all that remains is to transfer the my_android_apps.zip file to the sdcard, and then boot into recovery and install the zip file all of which can be done using ADB as follows:

$ adb push my_android_apps.zip /sdcard/
$ adb reboot recovery

Now, how hard can that be ? !!!


The above method installs your apps as system apps(the system/app/ folder). However, if you want your apps to be installed as user apps(just like when you installed them from the play store), you have to put your apk files in another directory data/app/ parallel to the system/app/ folder as shown below.

$ cd ~/custom_apps
$ mkdir -p data/app
$ cp ~/my_android_apps/* ~/custom_apps/data/app/

This however, is not sufficient. If you take a look at the “updater-script” file inside META-INF/ you will see that only the system partition is mounted. You will have to add a few lines to mount the data partition as well. For my Motorola Defy, I have the following lines in my updater-script.

run_program("/sbin/mount", "/dev/block/mmcblk1p21", "/system");
package_extract_dir("system", "/system");
run_program("/sbin/unmount", "/dev/block/mmcblk1p21", "/system");

run_program("/sbin/mount", "/dev/block/mmcblk1p25", "/data");
package_extract_dir("data", "/data");
run_program("/sbin/unmount", "/dev/block/mmcblk1p25", "/data");

The first 3 lines mount the system partition, extract the contents of the system/ directory in the zip file into this partition and unmounts the system partition. The next three lines do the same for the data partition. However, note that the device file names(mmcblk1p21 for system partition and mmcblk1p25 for data partition) are specific to my Motorola Defy and may not be the same for your android device. That said, finding out the device file names for the system and data partitions on your android device is not difficult at all. You can use adb to find out as shown below.

$ adb shell mount | grep '/system\|/data' -

You can also view the contents of /etc/recovery.fstab to find out the device file names. Just replace the device file names you see in the output of the above command(first column of the output) instead of the ones I have used above in the updater-script file.

That is all… You can now create the zip file using 7zip and flash it in recovery using the same steps as earlier.