Android 免安装应用:如何调试免安装应用? [英] Android Instant Apps: How to debug an instant app?

查看:58
本文介绍了Android 免安装应用:如何调试免安装应用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 Android Studio 上调试免安装应用时,调试器会附加到免安装应用进程并在大多数断点处暂停执行.然而,它似乎忽略了我主要活动的 onCreate 方法中的断点.我尝试过调试"和将调试器附加到 Android 进程"选项.我错过了什么?

When I debug my instant app on Android Studio, the debugger attaches to instant app process and pauses execution at most breakpoints. However it seems to ignore breakpoints at my main activity's onCreate method. I've tried "Debug" and "Attach Debugger to Android Process" options. What am I missing?

推荐答案

有关如何使用 Android Studio 调试器调试 Android 应用程序的基本信息,请访问 开发人员文档调试您的应用.

Basic information about how to use Android Studio debugger to debug an Android app is available at Developer Documentation Debug Your App .

Android Studio 调试器在调试免安装应用时大部分时间都能正常工作.但是,您会注意到,在运行 Android N 和下面.

Android Studio debugger works normally most of the time when debugging an instant app. However, you will notice that the debugger will fail to stop at breakpoints early in the app's lifecycle (such as Application.onCreate or Activity.onCreate) on devices running Android N and below.

当您的免安装应用启动并运行时,它会在您应用的程序包名称下运行.但是,在临时包名下运行时,应用程序启动过程中会有很短的时间,形式如下:

When your instant app is up and running, it runs under your app's package name. However, there is a short period of time during app startup when it runs under a temporary package name, in the following form:

com.google.android.instantapps.supervisor.isolated[0-9]+

这个临时名称由运行时分配.因为 Android Studio 不知道这个名字,所以调试器不会附加到这个进程.

This temporary name is assigned by the runtime. Because Android Studio is not aware of this name, the debugger will not attach to this process.

解决方法是找出这个临时名称并使用 adb 将应用程序设置为调试.这可以通过在运行您的应用程序之前在终端中运行以下命令来完成.它会在您的应用启动时打印出名称.

The workaround is to find out this temporary name and use adb to set the app to debug. This can be done by running the following command in terminal before running your app. It will print out the name when your app starts.

=> adb shell 'while true; do ps | grep com.google.android.instantapps.supervisor.isolated; sleep 1; done'
u0_i6     31908 630   1121664 29888          0 00ea57eed4 R com.google.android.instantapps.supervisor.isolated15

确定包名称后,使用以下命令将暂停并使您的免安装应用进程等待调试器.然后正常连接调试器,但通过单击显示所有进程"在选择进程"窗口中选择临时进程名称.

Once you identify the package name, use the following command which will pause and make your instant app process to wait for the debugger. Then attach the debugger normally, but choosing the temporary process name in the Choose Process window by clicking on "Show all processes".

=> adb shell am set-debug-app -w --persistent com.google.android.instantapps.supervisor.isolated15

这篇关于Android 免安装应用:如何调试免安装应用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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