我正在学习使用Android Studio 3.1.4在WearOS下开发表盘。我的调试器有问题。
似乎我无法直接在调试模式下(Shift-F9)运行该应用程序。如果这样做,尽管在手表(仿真器或真实手表(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.
如果我理解正确,则必须在手表本身上启动调试服务器。我该如何实现?
我要调试手表的唯一选择是在正常模式下(Shift-F10)运行应用程序,然后然后将调试器附加到进程中。
这是不理想的,因为它不允许我对代码的初始化过程进行故障排除。特别是initializeWatchFace()
,onCreate()
或onSurfaceChanged()
之类的方法无法调试,这确实很烦人。
在手表本身,清单上某处是否有什么特别的事情可以解决?是否可以将其链接到我的应用程序没有活动的事实(如Google CodeLab中所述)。我似乎有消息将这些问题与活动管理联系起来。
答案 0 :(得分:1)
另一种选择是覆盖表面服务上的onCreate
方法并调用Debug.waitForDebugger()
override fun onCreate() {
Debug.waitForDebugger()
super.onCreate()
}
在Android Studio中使用Run
,以便在手表中安装表盘服务。
然后在Android Studio中转到Run
顶部菜单,然后选择Attach to Process...
。
waitForDebugger
基本上将主线程置于暂停状态,直到连接了调试器为止。您可以将Debug.waitForDebugger
放在代码中更有意义的位置。
答案 1 :(得分:0)
恐怕除了您已经找到的解决方案外,没有其他真正的解决方案:正常启动表盘,然后将调试器连接到它。如您所料,问题是调试器正在等待Activity
的启动。由于表盘基于Service
,因此永远不会发生。
但是,您可以使用一些技巧来调试表盘启动代码。这是一种方法:
如果这不起作用,另一种方法是在应用程序中创建“虚拟”活动,使用Android Studio中的Shift-F9
进行调试,然后设置表盘。同样,所有的启动代码都应在建立调试器会话之后运行。
注意:调试表盘时您会发现的另一烦恼是,操作系统在调试器中停止运行几秒钟后将以ANR身份终止您的进程。除了快速之外,我没有找到其他解决方法!
答案 2 :(得分:0)
重新启动Android Studio对我有用。