Backup+ Lets You Backup Your App Data on Android Lollipop

Even though Android 5.0 Lollipop hasn’t yet seen its official release, quite … more

TechTalk Compiles All the Android News You Need in One App

If you’re as obsessed with mobile devices as the vast majority of our forum … more

Android App Review: Google Inbox to Improve Your Life – XDA TV

Recently, Google+ exploded with the announcement of Google Inbox, as … more

Damp the LG G3 Thermal Throttling

As our mobile devices grow thinner and more powerfulwith each passing generation, it’s inevitable … more
Post Reply

[GUIDE] Fix "assert failed: apply_patch_check" error

OP legom

20th October 2012, 01:29 AM   |  #1  
OP Junior Member
Thanks Meter: 26
 
20 posts
Join Date:Joined: Jul 2012
Overview:

This thread is a guide on how to fix the apply_patch_check error message experienced during an upgrade of the Android OS. Specifically, this will detail the steps for an upgrade of Jelly Bean from 4.1.1 to 4.1.2 on the Nexus 7 with CWM Recovery for a user of Windows. I'm sure similar steps will work for other recoveries/upgrades/devices and PC OSes.

You should only bother with this if you don't want to flash the entire system.img file to your phone, which is way easier.

Here is an example of the error message I'm talking about:
Code:
assert failed: apply_patch_check("/system/app/Chrome.apk", "819b34b66335c6faec86404d736a002b8871600", "9d6b55e63b0bf20bea433fb1ee7089f88ab73fb6")
E: Error in /sdcard/03a4eaf95f73.signed-nakasi-JZO54K-from-JRO03D.03a4eaf9.zip
(Status 7)
Installation aborted.
A few notes about the error:
  • This doesn't have to happen with the Chrome.apk specifically -- it could happen with any app in /system/app or .so in /system/lib.
  • Those random strings of numbers/letters are SHA-1 hashes of the apk.
    • The first one is the hash of the apk installed on your device. In my example, this happens to be the version of Chrome that comes with JB 4.1.2.
    • The second one is the expected hash of the apk that comes with JB 4.1.1.


Cause of the problem:

The reason this error occurs is because the file was somehow modified from its original state. In my case -- and most likely your case -- this was done by Titanium Backup. TB has an option to "Integrate updates of system apps into ROM", which will cause the apk in /system/app (and associated library files in /system/lib, if needed) to be overwritten with the updated apk.


Solution:
  1. Download this zip file which contains the full /system/app and /system/lib directory from the JB 4.1.1 factory image. *
  2. Extract the zip to a location of your choosing on your PC.
  3. In the extracted folder, locate the .apk or .so file referenced in the error message on your device.
  4. Copy this file to your device via your preferred method (USB cable works fine). I put my file in /sdcard/Download.
  5. On your device, use a root file explorer to move the file from /sdcard/Download to /system/app (or /system/lib).
    • If you don't have a program that can do this, I use ES File Explorer. Be sure to go to Settings > Root Settings and turn on Root Explorer, Up to Root, and Mount File System.
  6. Reboot into your Recovery and try to install the update again.
  7. Repeat steps 3-6 for each subsequent file that produces an error. You will basically need to do this for each app you integrated using TB and maybe a few library files, too. **


* Future updates (above 4.1.2):

Since I won't be keeping the zip file from step #1 up-to-date, here's how to get the directories that I included in the zip for yourself:
  1. Obtain a factory image for your device's current Android version (the version you're updating from).
    • For JB 4.1.1, this file is called nakasi-jro03d-factory-e102ba72.tgz.
    • If you're reading this guide at a later date, the JB 4.1.2 file is called nakasi-jzo54k-factory-973f190e.tgz.
    • You can try your luck at the official Google site, but they seem to only provide the version you're trying to update to, not from.
  2. Extract the .tgz file somewhere on your PC.
  3. Locate the image-naksi-jro03d.zip file and extract that, as well.
  4. In the folder you just extracted from the previous step, located the system.img file.
  5. Download and use a program called sgs2toext4 (Attachment 645320) to convert the system.img to system.ext4.img. ***
  6. Download and use a program called Linux Reader to open system.ext4.img.
    • Do this by going to Drives > Mount Image > Next > select your file.
    • It will then be listed under the Hard Disk Drives section in red as "Linux Ext Volume 1".
  7. Navigate to: Linux Ext Volume 1/system.
  8. Right-click on the app (or lib) directory and pick Save > Next > Output to dir of your choice.
  9. You now have the directories that were included with the zip file from Solution step #1, so just follow those steps now.


** How to avoid repeating steps:

If you'd rather not have to try to reinstall after updating only one file, just to find another file that needs updating, try this:
  1. Obtain the /system/app and /system/lib folders from the factory image and save them to your PC.
    • For the sake of this guide, let's say you save them to C:\factory_app and C:\factory_lib.
  2. Copy the /system/app and /system/lib directories from your phone to your PC.
    • For the sake of this guide, let's say you saved them to C:\phone_app and C:\phone_lib.
  3. Download the File Checksum Integrity Verifier utility from Microsoft.
  4. Start > Run > cmd
  5. fciv.exe -sha1 -xml factory_app.xml -wp C:\factory_app
  6. fciv.exe -sha1 -xml factory_app.xml -v -bp C:\phone_app
    • Don't ask me why, but you need to use -bp instead of -wp for the second command.
    • Don't forget the -v on the second command.
  7. The output of the last command will show you the list of files that are different. These are the files you need to take from C:\factory_app and put into the /system/app directory on your phone.
  8. Do the same for the lib directories (just replace all instances of "_app" with "_lib" in the previous commands).


Summary:

I hope that this post helped some of you who really didn't want to have to flash the system.img or wipe your device just to update. In the future, use TB to back up the original.

I wouldn't normally bother writing up a guide like this (it took almost as long to write as it did to figure out how to do this) but I couldn't find this solution anywhere even though I saw that I wasn't the only person with the problem. Sorry for not posting this guide sooner (update has been out for a while now), but the forum required me to make a bunch of useless spam posts before I could include any links in my guide and I didn't get around to making those posts right away.

*** I would like to thank balamu96m for his guide on extracting data from the system.img file and drphrozen for making the sgs2toext4 program.
Last edited by legom; 20th October 2012 at 03:24 PM.
The Following 26 Users Say Thank You to legom For This Useful Post: [ View ]
20th October 2012, 04:06 AM   |  #2  
MikesDroid's Avatar
Senior Member
Thanks Meter: 3
 
253 posts
Join Date:Joined: Sep 2007
More
Thanks for this. Will try now.

Worked great. Had to copy the apk and odex file.
Last edited by MikesDroid; 20th October 2012 at 04:31 AM.
20th October 2012, 04:50 AM   |  #3  
comminus's Avatar
Senior Member
Flag Vancouver
Thanks Meter: 559
 
618 posts
Join Date:Joined: Jul 2011
More
Good job! It's great to see the steps for Windows users!
20th October 2012, 05:28 AM   |  #4  
MikesDroid's Avatar
Senior Member
Thanks Meter: 3
 
253 posts
Join Date:Joined: Sep 2007
More
Just a heads up that I simply extracted the files I needed from and on my N7 using Root Explorer, without using my PC at all.
13th November 2012, 08:29 PM   |  #5  
Junior Member
Thanks Meter: 0
 
2 posts
Join Date:Joined: Feb 2011
Great guide! Method worked perfectly on my Nexus 7 going from 4.1.2 to 4.2, thanks
13th November 2012, 10:48 PM   |  #6  
Junior Member
Thanks Meter: 1
 
23 posts
Join Date:Joined: Nov 2012
Please... is there some other way to update the files w/o installing Java on my Windoze PeeCee? I accidentally messed up my YouTube.apk with Titanium Backup... now I can't update from 4.1.2 --> 4.2 JB.

EDIT: JavaPortable FTW... updating (fingers crossed)

EDIT: SUCCESS TY OP!
Last edited by simbin; 13th November 2012 at 11:38 PM.
13th November 2012, 11:03 PM   |  #7  
Junior Member
Thanks Meter: 1
 
2 posts
Join Date:Joined: Dec 2010
More
For anyone who flashed the 4.2 clock/keyboard already
Hey, for anyone who flashed the 4.2 clock and keyboard on their Nexus 7 already and need to roll back to do the 4.2 update, I used OP's method to make a flashable zip that puts the 4.1.2 clock and keyboard back.

Worked perfectly for my Nexus 7 to get me up and running. Hope it helps anyone!

cantthinkofa.com/files/RestoreClockKeyboard.zip
The Following User Says Thank You to zeroshade For This Useful Post: [ View ]
14th November 2012, 10:40 AM   |  #8  
Junior Member
Thanks Meter: 0
 
1 posts
Join Date:Joined: Nov 2012
galaxy nexus
Hi can you post a guide for galaxy nexus? Or if it is the same, can you post the link of JB factory image for galaxy nexus? Sorry, I can't find any thread for galaxy nexus, and I don't want to complete flash the stock image since I don't want to wipe my phone.

Thanks in advance!
14th November 2012, 11:28 AM   |  #9  
Junior Member
Thanks Meter: 0
 
1 posts
Join Date:Joined: May 2009
Smile Nice Guide
perfect, the guide works just fine. Now finally running 4.2.
14th November 2012, 08:43 PM   |  #10  
TheDKGunner's Avatar
Junior Member
Thanks Meter: 2
 
7 posts
Join Date:Joined: Jan 2011
Awesome guide... Thanks... Happily running 4.2 now aften beeing stuck at libutils.so...


Sent from my Nexus 7 using xda premium

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Nexus 7 Q&A, Help & Troubleshooting by ThreadRank