I recently had to help someone fix their Nexus 5 after it got caught in the infamous "optimising apps" boot loop. The only problem was I had no knowledge of Android whatsoever. I wasn't deterred -- it's just another flavour of Linux, after all -- and after stuffing around I got the device working again. Unsurprisingly, it was quite the learning experience.
Rather than write a lengthy guide on how to fix various Android software problems -- there are plenty of those already -- I'm going to highlight the important points that made the difference between giving up and actually performing a successful recovery:
Getting To Know ADB
The Android Device Bridge, or ADB, is a command line tool that comes with the Android SDK. Fortunately, you don't need the whole SDK to use it as "lite" packages of it are available. ADB allows you to issue commands to your Android device using your terminal window of choice.
At the most basic level, you can send and grab files and folders and it also offers a backup command if you need to fetch the kitchen sink. When all else fails, ADB can be the low level tool you need to get the job done.
The Nexus Root Toolkit Is Your Friend
The only problem with using ADB as I discovered is that certain commands are only available when the phone wants them to be. For example, from the recovery menu, you have the option to sideload. This opens up ADB access, but the only thing you can do is, well, sideload a custom ROM. If you want to do anything more sophisticated, you'll need to be in ADB's "recovery" mode (not to be confused with your phone's recovery area).
To the rescue is the Nexus Root Toolkit, which will allow you to boot a custom recovery ROM. Open the toolkit's Options menu and select the "Custom Recovery" tab. Then choose "Utilize ClockworkMod Touch Recovery by Koush" and save your changes. With the phone running at the bootloader screen, you can use the toolkit's "Advanced Utilities", specifically the "Custom Recovery" button under the "Fastboot Boot" group, to reboot the phone.
Once ClockworkMod is running, you'll find you can use almost all of ADB's command. Backup is the exception, as it requires user input from the operating system. There might be a way around this, but I wasn't able to find it. Which lead me to take the following actions.
Android Is Linux
Obvious, I know. But this means you have access to a lot of nifty shell tools. My situation was that I couldn't fix the phone -- after wiping the application cache, it still got caught up in the reboot cycle -- so I downgraded from "repair it" to "get all the data off it and reset". This proved harder than it sounds. First, the backup tools included with ClockwordMod and Team Win Recovery Project don't snag all your data.
It's possible to lose videos, photos and save games because these tools ignore the device's internal storage ( the "/data/media" folder). Sure, you can use Android's own backup to get most of this, but if your phone craps out unexpectedly, you might not have the opportunity. Even so, these aren't even totally reliable.
The other difficulty was a raw dump using "adb pull" would fail on oddly-named files. My only choice was to use the "tar" command, running on the phone itself, to collect all the files into one giant file and pull that. This means you'll need enough space on the device for the operation, but tar offers a number of compression switches to help in this regard.
I'm happy to report my gambit with tar worked. It collated everything in "data/media" -- all 4GB -- and using ADB I was able to grab this file. Something I did note is that ADB misreported the tar's size. By the time the pull was done, the progress bar was 8000 per cent complete. I was concerned briefly that the archive was corrupted, but 7-Zip expanded it with no complaints and none of the data the owner needed was damaged.
It's true, I wasn't able to restore the phone to its previous condition, but with all the data safely downloaded, resetting the phone was a less painful proposition. The only tricky part afterwards was getting a number of save game files back onto the phone, though this was quickly sorted via email (Dropbox was also an option) and ES File Explorer.