问题
I'm using several Firebase products in an Android app:
compile 'com.google.firebase:firebase-core:11.0.1'
compile 'com.google.firebase:firebase-database:11.0.1'
compile 'com.google.firebase:firebase-storage:11.0.1'
compile 'com.google.firebase:firebase-auth:11.0.1'
compile 'com.google.firebase:firebase-messaging:11.0.1'
One or more of these products seems to be using the WAKE_LOCK
permission. Possibly Analytics or FCM.
I can understand where it's needed. The problem however is that in the Google Play Console, in the Android Vitals section, Google warns me that the Stuck partial wake locks percentage is 2.30% which is larger than the Bad behavior threshold which is 0.70%. Similarly, the Background stuck partial wake locks is 1.40% which is again larger than the Bad behavior threshold which is 0.10%.
In other words, Google considers this number of wake locks a 'bad behavior'.
I don't use wake locks, so it seems that the issue is coming from the Firebase SDK.
Anyone knows what's causing that? Can we fix that?
回答1:
You can tell where Android manifest items come from by using Android Studio's Merged Manifest tab when viewing your app's manifest file. When you view this on you manifest, you'll see that WAKE_LOCK comes from firebase-iid.
To find out what includes firebase-iid, you can use gradle to show a dependency graph.
./gradlew dependencies
The output of this shows that it's included by both firebase-core and firebase-messaging:
+--- com.google.firebase:firebase-messaging:11.6.0
| +--- com.google.firebase:firebase-iid:11.6.0
| | +--- com.google.android.gms:play-services-basement:11.6.0 (*)
| | +--- com.google.firebase:firebase-common:11.6.0 (*)
| | +--- com.google.android.gms:play-services-tasks:11.6.0 (*)
| | \--- com.google.firebase:firebase-iid-license:11.6.0
| +--- com.google.android.gms:play-services-basement:11.6.0 (*)
| +--- com.google.firebase:firebase-common:11.6.0 (*)
| \--- com.google.firebase:firebase-messaging-license:11.6.0
\--- com.google.firebase:firebase-core:11.6.0
\--- com.google.firebase:firebase-analytics:11.6.0
+--- com.google.android.gms:play-services-basement:11.6.0 (*)
+--- com.google.firebase:firebase-common:11.6.0 (*)
+--- com.google.firebase:firebase-analytics-impl:11.6.0
| +--- com.google.android.gms:play-services-basement:11.6.0 (*)
| +--- com.google.firebase:firebase-iid:11.6.0 (*)
| +--- com.google.firebase:firebase-common:11.6.0 (*)
| +--- com.google.android.gms:play-services-tasks:11.6.0 (*)
| \--- com.google.firebase:firebase-analytics-impl-license:11.6.0
\--- com.google.firebase:firebase-analytics-license:11.6.0
There is nothing here that needs to be "fixed". Firebase simply makes use of wake locks to do its normal business. You can always try to remove the permission, but then Firebase may not work correctly any more. Just leave it alone.
来源:https://stackoverflow.com/questions/48255090/firebase-and-wake-locks-issue-in-android