https://kotlinlang.org logo
Title
f

florent

01/24/2023, 5:25 PM
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

Yingding Wang

01/24/2023, 10:59 PM
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

florent

01/25/2023, 9:26 AM
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

Yingding Wang

01/25/2023, 1:50 PM
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

florent

01/25/2023, 2:21 PM
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

Yingding Wang

01/25/2023, 4:18 PM
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
implementation libs.compose.ui.tooling
to
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

florent

01/25/2023, 4:53 PM
I have completely removed the tooling lib and it still doesn't trigger at all for me in release mode
l

louiscad

01/25/2023, 4:54 PM
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

Yingding Wang

01/25/2023, 5:07 PM
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

florent

01/25/2023, 5:12 PM
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

Yingding Wang

01/25/2023, 5:16 PM
oh, then it also clarifies why my production app build works, I also have
shrinkResources false
release {
    debuggable false
    minifyEnabled false
    shrinkResources false
l

louiscad

01/25/2023, 5:29 PM
You can start by adding the class that supports ambient mode
f

florent

01/25/2023, 5:32 PM
I have added
-keep class com.google.android.wearable.**
-keep interface com.google.android.wearable.**
-keep enum com.google.android.wearable.**
still doesn't work
l

louiscad

01/25/2023, 5:33 PM
Have you looked at which class is using reflection under the hood.
I'm on mobile FYI, I can't check for you
f

florent

01/25/2023, 5:35 PM
I am guessing that's the
WearableActivityController
but I don't think you can have the source code of it
y

Yingding Wang

01/25/2023, 5:38 PM
is this one
com.google.android.wearable.compat.WearableActivityController
f

florent

01/25/2023, 5:42 PM
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

louiscad

01/26/2023, 8:37 AM
I think there's a compileOnly dependency to have, do you have it?
f

florent

01/26/2023, 9:14 AM
Yes that fixes it thanks! I am gonna do a PR