【问题标题】:Android Instant Apps: How to debug an instant app?Android Instant Apps:如何调试 Instant App?
【发布时间】:2017-06-01 16:07:34
【问题描述】:

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

【问题讨论】:

    标签: android android-studio android-debug android-instant-apps


    【解决方案1】:

    有关如何使用 Android Studio 调试器调试 Android 应用的基本信息,请访问Developer Documentation Debug Your App .

    Android Studio 调试器大部分时间在调试免安装应用时都能正常工作。但是,您会注意到,在运行 Android N 及更低版本的设备上,调试器将无法在应用生命周期早期的断点处停止(例如 Application.onCreate 或 Activity.onCreate)。

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

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

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

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

    => 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
    

    确定包名称后,使用以下命令将暂停并让您的即时应用进程等待调试器。然后正常附加调试器,但通过单击“显示所有进程”在“选择进程”窗口中选择临时进程名称。

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

    【讨论】:

    • 可以通过调用 adb shell am clear-debug-app 清除调试状态
    【解决方案2】:

    我最近在调试免安装应用时也遇到了问题。 有多个日志消息

    “等待应用程序启动调试服务器”

    在调试窗口中并经过多次重试

    “无法连接到远程进程。正在中止调试会话。”

    我解决问题的方法是 使用 Android Studio “运行” 菜单中的“附加到进程” 选项。

    【讨论】:

    • OP 已经提到他尝试了“附加到进程”选项,但没有帮助。
    • 对我来说它工作正常,始终如一。 Android Studio 3.3
    • 遇到了同样的问题,但不幸的是,这对我不起作用,有什么更新吗?
    猜你喜欢
    • 1970-01-01
    • 2017-11-05
    • 1970-01-01
    • 1970-01-01
    • 2017-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多