gpt4 book ai didi

android - 调试 WatchFace 时永远为 "Waiting for application to start debug server"

转载 作者:行者123 更新时间:2023-11-29 00:59:55 27 4
gpt4 key购买 nike

我正在学习使用 Android Studio 3.1.4 在 WearOS 下开发表盘。我的调试器有问题。

看来我无法在 Debug模式 (Shift-F9) 下直接运行应用程序。如果我这样做,我会系统地收到以下消息,尽管在 watch (模拟器或真实 watch (Huawai Watch 2))上进行了授权调试:

08/24 09:03:00: Launching wearmodule
$ adb push /path/wearmodule/build/outputs/apk/debug/wearmodule-debug.apk /data/local/tmp/com.example.wearmodule
$ adb shell pm install -t -r "/data/local/tmp/com.example.wearmodule"
Success


Waiting for application to come online: com.example.wearmodule.test | com.example.wearmodule
Waiting for application to come online: com.example.wearmodule.test | com.example.wearmodule
Waiting for application to come online: com.example.wearmodule.test | com.example.wearmodule
Connecting to com.example.wearmodule
Waiting for application to start debug server
Waiting for application to come online: com.example.wearmodule.test | com.example.wearmodule
Connecting to com.example.wearmodule
Waiting for application to start debug server
Waiting for application to come online: com.example.wearmodule.test | com.example.wearmodule
Connecting to com.example.wearmodule
Waiting for application to start debug server
Waiting for application to come online: com.example.wearmodule.test | com.example.wearmodule
Connecting to com.example.wearmodule
Waiting for application to start debug server
Waiting for application to come online: com.example.wearmodule.test | com.example.wearmodule
Connecting to com.example.wearmodule
Waiting for application to start debug server
Waiting for application to come online: com.example.wearmodule.test | com.example.wearmodule
Connecting to com.example.wearmodule
Waiting for application to start debug server
Waiting for application to come online: com.example.wearmodule.test | com.example.wearmodule
Connecting to com.example.wearmodule
Waiting for application to start debug server
Waiting for application to come online: com.example.wearmodule.test | com.example.wearmodule
Connecting to com.example.wearmodule
Waiting for application to start debug server
Waiting for application to come online: com.example.wearmodule.test | com.example.wearmodule
Connecting to com.example.wearmodule
Waiting for application to start debug server
Waiting for application to come online: com.example.wearmodule.test | com.example.wearmodule
Connecting to com.example.wearmodule
Waiting for application to start debug server
Waiting for application to come online: com.example.wearmodule.test | com.example.wearmodule
Connecting to com.example.wearmodule
Waiting for application to start debug server
Waiting for application to come online: com.example.wearmodule.test | com.example.wearmodule
Connecting to com.example.wearmodule
Waiting for application to start debug server
Waiting for application to come online: com.example.wearmodule.test | com.example.wearmodule
Connecting to com.example.wearmodule
Waiting for application to start debug server
Waiting for application to come online: com.example.wearmodule.test | com.example.wearmodule
Connecting to com.example.wearmodule
Waiting for application to start debug server
Could not connect to remote process. Aborting debug session.

如果我理解正确,调试服务器必须在 watch 本身上启动。我怎样才能做到这一点?

如果我想调试我的 watch ,唯一的选择是在正常模式下运行应用程序 (Shift-F10),然后将调试器附加到进程。

这并不理想,因为它不允许我对代码的初始化过程进行故障排除。特别是像initializeWatchFace()onCreate()onSurfaceChanged() 这样的方法无法调试,真是烦人。

watch 本身、 list 中的某个地方是否需要做任何特别的事情来解决这个问题?它是否与我的应用程序没有 Activity 这一事实有关(如 Google CodeLab 中所教)。我似乎有消息将这些问题与 Activity 管理联系起来。

最佳答案

另一种选择是覆盖表盘服务上的 onCreate 方法并调用 Debug.waitForDebugger()

override fun onCreate() {
Debug.waitForDebugger()
super.onCreate()
}

在 Android Studio 中使用 Run,以便在 watch 中安装表盘服务。然后在 Android Studio 中转到 Run 顶部菜单并选择 Attach to Process...

waitForDebugger 基本上使主线程暂停,直到连接了调试器。您可以将 Debug.waitForDebugger 放在代码中更有意义的位置。

关于android - 调试 WatchFace 时永远为 "Waiting for application to start debug server",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51999417/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com