How to create your own FlashAfterUpdate ZIPs for Android

If you are running a custom Android ROM that you update often like me (more than 1 time a month), you want to industrialize the process of flashing additional system applications/configurations. Because without automation, you have to do the following to install a system APK back after update:

$ adb push BlankStore.apk /sdcard/
$ adb shell
su
mount -o remount,rw /system
mv /sdcard/BlankStore.apk /system/priv-app/
chmod 644 /system/priv-app/BlankStore.apk
mount -o remount,ro /system
reboot
$ echo Boring, isn\'t it?

I'm using OpenDelta that was built to provide automatic OTA updates for The OmniROM Project's nightly builds. Additionally, OpenDelta conveniently flashes ZIPs located in the FlashAfterUpdate subfolder of its storage. So, what you basically do is putting your flashable zips in /sdcard/OpenDelta/FlashAfterUpdate before running the OTA update.

In this article, I will show you how to create your own FlashAfterUpdate zips through 2 examples:

Create a flashable zip to install CaCert.org certificates automatically

$ mkdir -p /tmp/cacert/system/etc/security/cacerts/ # We create the hierarchical structure of directories that will contain our certificates
$ cd /tmp/cacert/system/etc/security/cacerts/
$ wget https://www.cacert.org/certs/root.crt
$ wget https://www.cacert.org/certs/class3.crt
$ cat root.crt > 5ed36f99.0
$ cat class3.crt > e5662767.0
$ openssl x509 -inform PEM -text -in root.crt -out /dev/null >> 5ed36f99.0
$ openssl x509 -inform PEM -text -in class3.crt -out /dev/null >> e5662767.0
$ rm root.crt class3.crt
$ cd /tmp/cacert
$ wget https://pub.jeekajoo.eu/misc/android/TEMPLATE_KEEP.zip -O cacert.zip # Download TEMPLATE_KEEP.zip into cacert.zip
$ zip -rv cacert.zip system/ # Add system directory to cacert.zip
updating: system/       (in=0) (out=0) (stored 0%)
  adding: system/etc/   (in=0) (out=0) (stored 0%)
  adding: system/etc/security/  (in=0) (out=0) (stored 0%)
  adding: system/etc/security/cacerts/  (in=0) (out=0) (stored 0%)
  adding: system/etc/security/cacerts/5ed36f99.0        (in=8294) (out=4385) (deflated 47%)
  adding: system/etc/security/cacerts/e5662767.0        (in=8392) (out=4396) (deflated 48%)
total bytes=408985, compressed=215878 -> 47% savings
$ echo 1st zip done!

Are you being lazy? Download mine.

$ wget https://pub.jeekajoo.eu/misc/android/cacert.zip

Create a flashable zip to install BlankStore automatically

$ mkdir -p /tmp/blankstore/system/priv-app/ # We create the hierarchical structure of directories that will contain our system APK
$ # Get latest release of Blank Store system APK and copy it to /tmp/blankstore/system/priv-app/
$ cd /tmp/blankstore # Go back to the root of our working directory
$ wget https://pub.jeekajoo.eu/misc/android/TEMPLATE_KEEP.zip -O BlankStore.zip # Download TEMPLATE_KEEP.zip into BlankStore.zip
$ zip -rv BlankStore.zip system/ # Add system directory to the BlankStore.zip
updating: system/       (in=0) (out=0) (stored 0%)
updating: system/priv-app/      (in=0) (out=0) (stored 0%)
  adding: system/priv-app/BlankStore.apk        (in=549262) (out=531147) (deflated 3%)
total bytes=1044036, compressed=838558 -> 20% savings
$ unzip -t BlankStore.zip # Test unzipping (without actually unpacking files)
Archive:  BlankStore.zip
    testing: META-INF/                OK
    testing: META-INF/CERT.RSA        OK
    testing: META-INF/CERT.SF         OK
    testing: META-INF/com/            OK
    testing: META-INF/com/google/     OK
    testing: META-INF/com/google/android/   OK
    testing: META-INF/com/google/android/update-binary   OK
    testing: META-INF/com/google/android/updater-script   OK
    testing: META-INF/MANIFEST.MF     OK
    testing: system/                  OK
    testing: system/app/              OK
    testing: system/media/            OK
    testing: system/priv-app/         OK
    testing: system/priv-app/BlankStore.apk   OK
No errors detected in compressed data of BlankStore.zip.
$ echo 2nd zip done!

Are you being lazy? Download mine:

$ wget https://pub.jeekajoo.eu/misc/android/Blankstore_0.7.4.zip

Push flashable zips to FlashAfterUpdate directory

$ adb push /tmp/cacert/cacert.zip /sdcard/OpenDelta/FlashAfterUpdate # Push the 1st ZIP we created
$ adb push /tmp/blankstore/BlankStore.zip /sdcard/OpenDelta/FlashAfterUpdate # Push the 2nd ZIP we created
$ adb push /tmp/UPDATE-SuperSU-v2.46.zip /sdcard/OpenDelta/FlashAfterUpdate # Push SuperSU
$ echo "Done! You can now run an OTA update and have all those goodies flashed automatically :)"