Android Instant Apps: How to debug an instant app?

前端 未结 2 1139
时光取名叫无心
时光取名叫无心 2021-01-12 19:59

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

2条回答
  •  生来不讨喜
    2021-01-12 20:16

    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
    

提交回复
热议问题