I'm using AmbientModeSupport for an Androi Wear OS application: https://developer.android.com/training/wearables/overlays/always-on
Just finished implementing/testing it and everything worked as expected. After app release I noticed that the feature is not working properly when the app is downloaded from Google Play.
I did some extra testing and:
- Everything works if app is installed in debug-mode.
- The Ambient feature is not working well if app is installed in release-mode.
In release-mode, the screen just lowers it's brightness, but there are no changes on the UI (changes performed in onEnterAmbient). The WAKE_LOCK permission is already provided in AndroidManifest:
<uses-permission android:name="android.permission.WAKE_LOCK" />
Any ideas?
UPDATE: After I thought I'm completely out of ideas, I realized that my build.gradle has 2 extra things for the release-mode, the proguard and the minify flags:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
It seems that the minifyEnabled caused the problem. I don't know why this behavior occured, but the Ambient Mode is working if I remove the minifyEnabled flag.
I was having the same issue within my Flutter app, and my build.gradle file did not explicitly have
minifyEnabledset to true, but it is the default in release mode. For flutter you also need to setshrinkResourcesto false (because it is set to true by default also in release mode, and ifminifyEnabledis false thenshrinkResourcesmust be also be false. Flutter will error on build if you do not do this).(within
android\app\build.grade):Once I did this Ambient mode support also worked in release mode.