flutter / samples

A collection of Flutter examples and demos
https://flutter.github.io/samples/
Other
17.21k stars 7.51k forks source link

[add_to_app/android_view] Is flutter working with WearOS watchface? #924

Closed thaihuynhxyz closed 3 years ago

thaihuynhxyz commented 3 years ago

We usually build watch face on WearOS with OpenGL by Gles2WatchFaceService. When I try the android_view sample, I have thought if Flutter can draw on a FlutterSurfaceView, can it draw on WatchFaceService.Engine.SurfaceHolder.Surface? It will be very productive if we can develop watch faces on Flutter instead of OpenGL.

I have tried to create a watchface sample here.

The sample runs well without error. In the logcat I see the dart isolate already executed, the CellWidget already init. But the watch is still black.

10/08 12:17:26: Launching 'app' on Wear OS Square API 30.
Install successfully finished in 2 s 982 ms.
Connected to process 7213 on device 'Wear_OS_Square_API_30 [emulator-5554]'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
    No Network Security Config specified, using platform default
I/ResourceExtractor: Found extracted resources res_timestamp-1-1633666192663
    Resource version mismatch res_timestamp-1-1633670250745
I/ResourceExtractor: Extracted baseline resource assets/flutter_assets/kernel_blob.bin
I/ResourceExtractor: Extracted baseline resource assets/flutter_assets/vm_snapshot_data
I/ResourceExtractor: Extracted baseline resource assets/flutter_assets/isolate_snapshot_data
W/utter.watchface: type=1400 audit(0.0:61): avc: denied { read } for name="max_map_count" dev="proc" ino=94404 scontext=u:r:untrusted_app:s0:c65,c256,c512,c768 tcontext=u:object_r:proc_max_map_count:s0 tclass=file permissive=0 app=org.demen.flutter.watchface
D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
D/HostConnection: HostConnection::get() New Host Connection established 0xe8f64b30, tid 7213
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_2 
D/EGL_emulation: eglCreateContext: 0xe8f64890: maj 2 min 0 rcv 2
    eglCreateContext: 0xe8f63470: maj 2 min 0 rcv 2
D/HostConnection: HostConnection::get() New Host Connection established 0xe8f688e0, tid 7240
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_2 
D/EGL_emulation: eglMakeCurrent: 0xe8f63470: ver 2 0 (tinfo 0xe92b6650) (first time)
D/FlutterViewEngine: attachToService: service=org.demen.flutter.watchface.MyWatchFace@da85688
D/FlutterViewEngine: attachHolder: holder=android.service.wallpaper.WallpaperService$Engine$1@efd3607
    hookServiceAndHolder
I/Gralloc4: mapper 4.x is not supported
D/HostConnection: createUnique: call
    HostConnection::get() New Host Connection established 0xe8f67220, tid 7239
D/goldfish-address-space: allocate: Ask for block of size 0x100
    allocate: ioctl allocate returned offset 0x3fbffe000 size 0x2000
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_2 
D/HostConnection: HostConnection::get() New Host Connection established 0xe8f67a00, tid 7239
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_2 
D/EGL_emulation: eglMakeCurrent: 0xe8f64890: ver 2 0 (tinfo 0xe92ba470) (first time)
D/EGL_emulation: eglCreateContext: 0xe8f66ea0: maj 2 min 0 rcv 2
I/flutter: Observatory listening on http://127.0.0.1:35795/a70OVSm-Dnc=/
D/FlutterViewEngine: onVisibilityChanged: visible=false
D/FlutterViewEngine: onVisibilityChanged: visible=true
I/flutter: _CellState.initState

watchface

RedBrogdon commented 3 years ago

@thaihuynhxyz, I'm impressed by your bravery in trying to get Flutter running on a watch!

It's not actually something the SDK officially supports, though, as you can see from this issue:

https://github.com/flutter/flutter/issues/2057

thaihuynhxyz commented 3 years ago

@RedBrogdon , thank you for your replying. It's not the same with the Android Wear app support, as the watch face project has no Activity. I see the way the flutter team connects a SurfaceView with Flutter's Dart isolate in the add_to_app/android_view example, so I just want to ask in case the WatchFaceService provide a SurfaceHolder is it available to do the same thing without Activity context?

thaihuynhxyz commented 3 years ago

@RedBrogdon I did it. Just missing setViewportMetrics. Should I add that sample to add_to_app/android_watchface

watchface

RedBrogdon commented 3 years ago

Wow. That's legitimately amazing.

You should totally add it to your sample (though make sure to attribute the clock code properly, since it's MIT licensed).

This repo wouldn't be a good place for that code to be maintained in the long run, since anything stored here is expected to be maintained by Google's Flutter team (and to be quite honest, I know nothing about Wear OS!). If you do add that code to your fork, though, I'd be happy to direct some attention to it using social media. I imagine there will be plenty of Flutter devs interested in what you've learned in building it.