Search code examples
androidgoogle-playupgradeandroid-install-apk

How to debug an app upgrade in Android Studio on a USB connected device


I have the production release of my Google Play Store app on my phone and have an updated version of the app in Android Studio. I would like to test the upgrade process, but have run into a versioning problem, then a logging problem.

To get a "clean" install, I can go into my phone's settings Backup & reset > Automatic restore, turn that off, then de-install the app, and install it from the Play Store. Alternatively, I could download the production APK and install it from the adb command line (details below). The result is my device should be the same as a regular production user.

Not directly germane to the question, but to understand my motivation for watching the upgrade process is that the app has an SQLite database and I extend SQLiteOpenHelper, so onUpgrade() is called, and some database schema work is being done.

Update Incompatible

If I click the button to deploy the app, then select my connected device, it wants to uninstall before proceeding:

Installation failed with message Failed to finalize session : INSTALL_FAILED_UPDATE_INCOMPATIBLE

Obviously I could uninstall, but that would not test the upgrade process!

Generating Signed APK

I built a "release" APK, using Generate Signed APK..., which is the same process I use when generating a release for uploading to the Play Store. This gets around the versioning problem, but causes a logging visibility problem. The release configuration used in the past and now looks like this:

Release build type used for production apk

Installing APK to the device from Command Line

"C:\Program Files (x86)\HTC\HTC Sync Manager\HTC Sync\adb" install -r app-release.apk

The above did upgrade without uninstalling. The process I used was to open Terminal within Android Studio, change directory to where the generated APK was stored, then type the above command.

Logging / Debugging Problems

The adb command line triggered the upgrade process, but it did not start feeding the Logcat window immediately with debug information. I could connect to Logcat for all processes, but I could not get debug information for just my process, and did not have access to debugging tools.

Logcat window shows No Debuggable Processes

Question

How can I start with a device that's running a signed production release then cause an updated version, contained in Android Studio, to run, without uninstalling, and with the ability to see the debugging output during the upgrade process? Or how can I modify a signed production release such that it allows an new version to update and allow debugging?


Solution

  • Because you're starting with an APK that is Debuggable=false, your work-around that includes building an update to the app using the same process as your production release process and getting a Logcat with all processes is probably the best you can do.

    Rebuilding from Previous Source Control Version

    One option would be to pull the specific version of the app out of your source control system and build it with Debuggable=true, and use that generated APK as your starting point instead of using the APK from the Play Store.

    For the Future

    Instead of making only one APK release version and uploading that to Play Store, make two versions. One version would be signed and uploaded as usual. And with the exact same source code, make another APK that has Debuggable=true. Rename each file with the version number. Then, later, if you ever want to try an upgrade from any version to any version, you can do that, and still have debugging capability.