Getting verification error when attempting to "adb sideload" the OTA update on Nexus 7 (2013) Notes:


Tablet is unlocked and rooted (SuperSU Pro v1.75)
I have the following recovery flash in place: TWRP 2.6.3.0, but I am booting stock recovery for the adb sideload invocation
The drivers are installed, host is Win 7 x64 and the device is detected in every mode (MTP, USB debug, bootloader)


When attempting to adb sideload (via stock recovery) the file 7d9b309e11da82edb5373a1f59965bca89f6041f.signed-razor-KRT16S-from-JSS15R.7d9b309e.zip on my Nexus 7 (2013) [Wi-Fi], I receive an error:

Finding update package...
Opening update package...
Verifying update package...
Installing update...
Verifying current system...
"/system/app/Drive.apk" has unexpected contents.
E:Error in /tmp/update.zip
(Status 7)
Installation aborted.


What am I doing wrong? What do I have to change in order to make the adb sideload succeed?
Goal

If you have the OTA image downloaded and, as in my case, ended up without success you should be able to adb sideload &lt;filename&gt; it still manually (video here).

Problem/Error

... unfortunately the OTA update via adb sideload errors out with:

Finding update package...
Opening update package...
Verifying update package...
Installing update...
Verifying current system...
"/system/app/Drive.apk" has unexpected contents.
E:Error in /tmp/update.zip
(Status 7)
Installation aborted.


where /system/app/Drive.apk could be any system app.

Who's not to blame?


TWRP is not to blame, I thought so in the beginning, but it would work with TWRP as well.
TitaniumBackup Pro. Since I rooted my device and use a power-user feature, I should have known of its side-effects. Now I do know, though :) ... and there's a good chance you learn about this from this answer now.


Apparent cause of the error

Using Titanium Backup Pro I had used the "freeze" feature to get rid of some of the system apps, namely:


ASUS Keyboard
Calendar
Calendar Storage
com.android.providers.partnerbookmarks
com.android.sharedstoragebackup
com.google.android.voicesearch
Exchange Services
Gmail
Google One Time Init
Google Play Books
Google Play Games
Google Play Magazines
Google Play Movies
Google Play Music
Google Search
Google Text-to-speech Engine
Hangouts
iWnn IME
iWnnIME Keyboard (White)
One Time Init


This was apparently why the adb sideload bailed out early with the error message given in my question.

I also uninstalled some of the system apps, and I think I remember "Drive" (remember?: /system/app/Drive.apk) was one of them.

The solution

I found the solution over at forum.xda-developers.com in this answer. The gist is that if you have a modified image, you need to restore that to make the OTA sideload succeed.

First download the stock image for the build you currently have. Make sure it's the correct one for your device. So I was trying to upgrade from JSS15R to KRT16S on the Wi-Fi version, which meant I needed to download the 4.3 (JSS15R) image. That was the file razor-jss15r-factory-ec2d4f76.tgz in my case. I then unpacked that which gave me a subfolder named razor-jss15r. Inside of it there were shell scripts, a .img file and a .zip (image-razor-jss15r.zip). The latter needed to be unpacked. Then I had the .img files in the folder I unpacked the .zip into:


boot.img
cache.img
recovery.img
system.img
userdata.img


Then I followed the steps outlined in the linked answer:


boot into bootloader (keep Volume-down and Power pressed directly after turning it on)
connect USB (make sure before that, that all USB drivers are installed)
change into the folder with the previously unpacked .img files
check from the Android SDK prompt that you see the device with fastboot devices.
then execute fastboot flash system system.img which will flash a stock system partition


Note: unlike in the linked post, I left out the step with the fastboot erase system because that is apparently implied by fastboot flash system system.img as can be seen from the output. I also left out fastboot flash boot boot.img and fastboot flash recovery recovery.img because I thought it was unlikely that these "partitions" had been modified (I was right). You may need the latter two, though. It would probably depend on what you have modified that prevents the adb sideload step (i.e. read and understand the error message).

Here's the output:

# fastboot flash system system.img
erasing 'system'...
OKAY [  1.160s]
sending 'system' (603447 KB)...
OKAY [ 19.786s]
writing 'system'...
OKAY [ 26.720s]
finished. total time: 47.668s


Et voila, a clean system that can be OTA updated.

So in short, you may only need to fastboot flash system system.img from the stock image you are running, if you ever get an error during the verification phase:

Verifying current system...
"/system/&lt;SOME&gt;.apk" has unexpected contents.
E:Error in /tmp/update.zip
(Status 7)


Download for factory images (Nexus 7, both)


Factory Images "razor" for Nexus 7 [2013] (Wi-Fi)
Factory Images "razorg" for Nexus 7 [2013] (Mobile)