Hi I am trying to implement the ambient mode. I ha...
# compose-wear
f
Hi I am trying to implement the ambient mode. I have followed that sample https://github.com/android/wear-os-samples/tree/main/AlwaysOnKotlin and it is the same issue, it works fine on debug but not at all on release mode, the ambient mode isn't triggered
y
What is the compose version and hardware you are experiencing this issue? I just pushed my release build with ambient mode a couple days ago, the ambient mode is triggered in my case properly. Is it maybe an AlarmManager related issue for the particular example? I am still in compose 1.3.x and wear compose 1.1.0. My ambient update works on pixel watch, tic watch pro.
f
It doesn't seems to be compose related, the ambient state isn't emitted from the wearable controller in release mode. I have tried on emulator and on Samsung watch 4
y
In debug mode the ambient state for the AlwaysOnKotlin example works for me. I will try to test it with a release mode. The GW4 of mine has some general issues, such as AOD also not working. I probably will not use GW4 as reference. Can you test your release build using alwaysOn with another watch hardware?
f
I tried with a pixel watch a it is the same result
At the refresh 15 it tries to go to ambient mode and somehow it fails
y
I can confirm, the issue stated by @florent on my pixel watch with the newest Jan 2023 update too. Debug build goes to ambient mode, a release build of the “AlwaysOn” example doesn’t trigger the ambient update. Although, I can see the screen will be dimmed a little bitte as shown in the video by florent.
I think there might be multiple issues in the `alwaysOn`example. For release build, we shall use
tooling.preview
, so I changed
Copy code
implementation libs.compose.ui.tooling
to
Copy code
implementation libs.compose.ui.tooling.preview
debugImplementation libs.compose.ui.tooling
Update: I turn off my wifi. The ambient mode on the new release build seems to be triggered, the time stopped ticking, but the screen still shows active mode. And after around 30 secs, the time ticks again and stops after that.
f
I have completely removed the tooling lib and it still doesn't trigger at all for me in release mode
l
I think ambient mode support relies on reflection in some way, and R8 breaks it. You might want to look a bit into it and see if there are some keep rules to add
y
I haven’t added any rule to the
<http://proguard-rules.pro|proguard-rules.pro>
before. Is there any tutorial shows how i can do it for the ambient mode?
f
Looks like it, if I put only -dontobfuscate and -dontoptimize it still fails but with -dontshrink it works ok. It must be removing needed stuff
y
oh, then it also clarifies why my production app build works, I also have
shrinkResources false
Copy code
release {
    debuggable false
    minifyEnabled false
    shrinkResources false
l
You can start by adding the class that supports ambient mode
f
I have added
Copy code
-keep class com.google.android.wearable.**
-keep interface com.google.android.wearable.**
-keep enum com.google.android.wearable.**
still doesn't work
l
Have you looked at which class is using reflection under the hood.
I'm on mobile FYI, I can't check for you
f
I am guessing that's the
WearableActivityController
but I don't think you can have the source code of it
y
is this one
com.google.android.wearable.compat.WearableActivityController
f
they probably have updated the implementation under the hood and haven't updated the r8 rules
I think it is missing
com.google.android.wearable.WearableSharedLib
but even with a -keep rule it doesn't seems to stay in
l
I think there's a compileOnly dependency to have, do you have it?
f
Yes that fixes it thanks! I am gonna do a PR
112 Views