Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Instant Apps: How to debug an instant app?

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?

like image 433
ibrahimkarahan Avatar asked Jun 01 '17 16:06

ibrahimkarahan


1 Answers

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
like image 124
ibrahimkarahan Avatar answered Sep 18 '22 12:09

ibrahimkarahan