Android Instant Apps: How to debug an instant app?

谁都会走 提交于 2019-12-01 01:58:46

问题


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?


回答1:


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

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]+

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.

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



回答2:


I had also problems recently debugging instant apps. with multiple log messages

"Waiting for application to start debug server"

in the debug window and after several retrials

"Could not connect to remote process. Aborting debug session."

The way I solved the issue is by using the "Attach To Process" option from Android studio "Run" menu.



来源:https://stackoverflow.com/questions/44312415/android-instant-apps-how-to-debug-an-instant-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!