Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forever "Waiting for application to start debug server" when debugging a WatchFace

I'm learning to develop watch faces under WearOS, with Android Studio 3.1.4. I have issues with the debugger.

It seems I can't run the application directly in debug mode (Shift-F9). If I do so, I systematically get the following message, despite having authorized debugging on the watch (emulator or real 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.

If I understand correctly, a debug server has to start on the watch itself. How can I achieve that?

The only option if I want to debug my watch is to run the app in normal mode (Shift-F10) and then attach a debugger to the process.

This is not ideal because it does not allow me to troubleshoot the initialization process of my code. In particular, methods like initializeWatchFace(), onCreate() or onSurfaceChanged() can't be debugged, which is really annoying.

Is there anything special to be done on the watch itself, in the manifest, somewhere, to fix this? Can it be linked to the fact that my app has no activity (as taught in the Google CodeLab). I've seem messages linking these issues to activities managment.

like image 862
cyphics Avatar asked Aug 24 '18 07:08

cyphics


People also ask

What is waiting for debugger?

This setting allows the execution of an app to be paused until a debugger is attached to it, upon the launch of the app. The app to debug must first be selected using the Debug app option.

What is Debuggable application?

Android allows the attribute android:debuggable to be set to true in the manifest, so that the app can be debugged. By default this attribute is disabled, i.e., it is set to false , but it may be set to true to help with debugging during development of the app.


1 Answers

Another option is to override the onCreate method on your watch face service and call Debug.waitForDebugger()

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

Use Run in Android Studio so your watch face service is installed in your watch. Then in Android Studio go to the Run top menu and there select Attach to Process....

waitForDebugger basically puts the main thread on pause until a debugger has been attached. You can place Debug.waitForDebugger wherever it makes more sense in your code.

like image 120
jush Avatar answered Oct 18 '22 14:10

jush