November 16, 2009

Solving the Android "Grayed Out Application" Deadlock

Greetings. Since I'm fairly vocal in my support of -- and enthusiasm for -- Google's Android OS, I tend to have quite a few people who send me their own Android experiences, both pro and con.

While by far most of these notes are positive, there has been a recurring theme lately of reported deadlocks involving already installed applications on Android phones. Previously installed applications suddenly wouldn't run, couldn't be uninstalled, and couldn't be reinstalled. Apparently no "official" explanation or cure for this condition has been apparent.

I wasn't in a position to investigate this myself until a few days ago, when a significant number of apps on my Android 1.6 G1 phone suddenly entered this "zombie" state, triggering my looking at the situation rather intently.

The primary symptom of these unusable apps is that not only won't they run directly, but the Android "Market" mechanism refuses to either "Open" or "Uninstall" them -- those options are grayed out. But since Market believes the apps are still installed, they cannot be reinstalled either.

Even with a rooted phone, this presents a quandary -- on a non-rooted phone, even more so.

Here are the results of my investigation into this issue, and my recommended procedure for recovery from such situations without completely resetting your phone and having to manually rebuild your entire configuration from scratch.

The basic problem appears to occur when (for whatever reason) an installed app's "apk" file has vanished from /data/app (or /data/app-private). Once this occurs the market app apparently goes out of sync, and then the affected programs won't run, can't be uninstalled, and can't be reinstalled -- via market directly, anyway.

The trick out of this dilemma is to obtain the original apk files that are missing. If you already have backups of these files, you can reinstall them via the app package manager. In my case, I used the Astro file manager to select the app apk files for which I had backups -- Astro then executes the package manager.

The affected programs will appear to already be installed -- that is, the app package manager will offer an UNINSTALL choice, not an INSTALL choice. Go ahead and tap UNINSTALL. When the uninstall finishes, go back to the package (e.g. via Astro again), then back to the package manager, and this time tap the offered INSTALL. The app should reinstall and be good to go.

It may also be possible to follow a similar sequence via the Android "adb" tool externally, but I had mixed results trying this, so I recommend working on the phone itself if possible, from backups on the sd card. The adb tool is still useful in this context for file copying operations -- see below.

If you don't have backups of the necessary apk files for the desired apps, you need to get them, but as noted above, market won't let you download them since it thinks they're already installed. Here's how to get them.

First, use Nandroid to back up the current state of the phone. I can't emphasize enough the value of Nandroid -- it's extremely useful. Once you have a Nandroid backup, do a factory data reset ("wipe") and reboot. You'll need to re-authenticate the phone to Google (that is, login with your Google account). Now go to the market program and install the programs for which you were missing apk files earlier -- you should be able to download them successfully now.

Once they've downloaded and installed, the new apk files should be in /data/app (or in some cases, /data/app-private). Copy the files (e.g. "cp") from the /data/app or /data/app-private dirs to the sd card (/sdcard). You can do this via a terminal console on the phone or through the "adb shell" command.

Now reboot, then restore the Nandroid backup that you made before doing the factory reset wipe.

After you're back in the previously saved system, you can navigate (e.g., with Astro) to the new apk files that you copied to the sd card, and follow the procedure above to first "uninstall" and then "install" those programs through the app package manager.

Using these techniques, I was able to completely restore all apps on my G1 that had mysteriously found themselves in the limbo of the unusable "grayed out" state. Why the apk files vanished from /data/app in the first place, triggering this entire sequence of events, remains a mystery to me at this point.

If I can be of any further assistance, please let me know.

--Lauren--

Posted by Lauren at November 16, 2009 02:40 PM | Permalink
Twitter: @laurenweinstein
Google+: Lauren Weinstein