如何在 USB 连接的设备上调试 Android Studio 中的应用程序升级 [英] How to debug an app upgrade in Android Studio on a USB connected device

查看:42
本文介绍了如何在 USB 连接的设备上调试 Android Studio 中的应用程序升级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的手机上有 Google Play 商店应用的正式版,Android Studio 中有应用的更新版本.我想测试升级过程,但遇到了版本控制问题,然后是日志记录问题.

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.

要获得干净"安装,我可以进入手机的设置 Backup &重置 >自动恢复,关闭它,然后卸载应用程序,然后从 Play 商店安装它.或者,我可以下载生产版 APK 并从 adb 命令行安装它(详情如下).结果是我的设备应该和普通生产用户一样.

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.

与问题没有直接关系,但要了解我观看升级过程的动机是该应用程序有一个 SQLite 数据库并且我扩展了 SQLiteOpenHelper,所以 onUpgrade() 被调用,并且正在完成一些数据库模式工作.

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.

如果我点击按钮部署应用程序,然后选择我连接的设备,它想在继续之前卸载:

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

安装失败并显示消息无法完成会话:INSTALL_FAILED_UPDATE_INCOMPATIBLE

Installation failed with message Failed to finalize session : INSTALL_FAILED_UPDATE_INCOMPATIBLE

显然我可以卸载,但是那不会测试升级过程!

我使用 Generate Signed APK... 构建了一个发布"APK,这与我在生成发布以上传到 Play 商店时使用的过程相同.这解决了版本控制问题,但会导致日志可见性问题.过去和现在使用的发布配置如下所示:

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:

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

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

以上确实升级,无需卸载.我使用的过程是在 Android Studio 中打开 Terminal,将目录更改为存储生成的 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.

adb 命令行触发了升级过程,但它并没有立即开始向 Logcat 窗口提供调试信息.我可以为所有进程连接到 Logcat,但我无法获取仅我进程的调试信息,并且无法访问调试工具.

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.

如何从运行已签名生产版本的设备开始,然后在不卸载的情况下运行包含在 Android Studio 中的更新版本,并且能够在升级过程中查看调试输出?或者我如何修改已签名的生产版本,使其允许更新新版本并允许调试?

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?

推荐答案

因为您从 Debuggable=false 的 APK 开始,您的解决方法包括构建应用程序的更新使用与您的生产发布流程相同的流程并获取包含所有流程的 Logcat 可能是您能做的最好的事情.

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.

一种选择是从源代码管理系统中提取特定版本的应用程序并使用 Debuggable=true 构建它,然后使用生成的 APK 作为起点而不是使用 APK来自 Play 商店.

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.

与其只制作一个 APK 发布版本并将其上传到 Play 商店,不如制作两个版本.一个版本将像往常一样被签名和上传.并使用完全相同的源代码,制作另一个具有 Debuggable=true 的 APK.使用版本号重命名每个文件.然后,以后如果您想尝试从任何版本升级到任何版本,都可以这样做,并且仍然具有调试功能.

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.

这篇关于如何在 USB 连接的设备上调试 Android Studio 中的应用程序升级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆