Android Instant Apps:如何调试即时应用程序? [英] Android Instant Apps: How to debug an instant app?

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

问题描述

当我在Android Studio上调试即时应用程序时,调试器会附加到即时应用程序进程中,并在大多数断点处暂停执行.但是,它似乎忽略了我主要活动的onCreate方法中的断点.我尝试了调试"和将调试器附加到Android Process"选项.我想念什么?

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及更低版本的设备上,调试器将无法在应用程序生命周期的早期阶段(例如Application.onCreateActivity.onCreate)的断点处停止.

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 Instant Apps:如何调试即时应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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