“Service MeasurementBrokerService is in use” is sh

2019-01-22 20:56发布

问题:

I have encountered an issue that GooglePlayServices app is using my application process for their service and also showing the processes count as 2.
I have attached the screenshot for the same. I have no idea why it is happening.
It is taking more memory compare to my app process.


Someone please can help me on this.


Showing two processes here

回答1:

I encountered this today after I added gcm to my app and can't figure out what exactly is the use of this MeasurementBrokerService. The only thing I found was this comment:

"I also had it and guess it is related to notification listener since it appears that Preventing macrodroid's notifications access make it stop. ( hope i m clear, my english is only remaining of school times...)"

from here



回答2:

We've seen this service show up as well. The issue turned out to be using Google Analytics along with a NotificationListenerService.

For some reasons these two things didn't play well together and caused MeasurementBrokerService to be always running, and consuming a significant amount of memory.

The solution for us was to remove Google Analytics for an alternative analytics solution.



回答3:

People who still check this thread for an answer, I have found a solution and posted an answer at:

what is Google Play services MeasurementBrokerService and how to stop it?

I checked that somehow still google AppMeasurement service was running on my device.

I have resorted to using the following approach:

The following stops data collection by firebase.

https://firebase.google.com/support/guides/disable-analytics tells us the following approach

<meta-data android:name="firebase_analytics_collection_deactivated" android:value="true" />

This alone still can't stop the appMeasurement from initializing.

The second step that has solved is adding the following to the app level gradle file:

configurations {
    all*.exclude group: 'com.google.firebase', module: 'firebase-core'
}

This basically removes all the code that firebase analytics uses.

In case it still doesn't work, make sure that the gradle does not include broad play service dependency

eg: compile

'com.google.android.gms:play-services-location:10.0.1'

instead of

'com.google.android.gms:play-services:10.0.1'

Worst case and i have not tested this as the above solved it for me is:

https://developers.google.com/analytics/devguides/collection/android/v4/advanced

Google should really stop putting unwanted things without the dev's permission IMHO. Hope this helps someone



回答4:

Exclude firebase-core libraries in your gradle file. I have faced the same issue.

configurations {
all*.exclude group: 'com.google.firebase', module: 'firebase-core'

}

For more details about firebase libraries just go through following link

http://blog.safedk.com/technology/mobile-sdks-firebase-or-play-services/



回答5:

This could be related to your Google Analytics integration in your app. Remove the Google Analytics references from your Java code, project level and App level gradle files. This leak is happening only in the latest Google Analytics versions. You can integrate the old Google Play Services versions like 7.3.0 which doesn't have this issue to fix this leak.



回答6:

I could manage to solve the issue by setting back Gradle version to 2.0.0 from 2.3.2. Because of this I had to set Gradle wraper to 2.14.1 from 3.3.

Also I set back to buildToolsVersion '23.0.1' from buildToolsVersion '25.0.2'.

By compiling the project like this, probably made many changes in the build environment, because when I changed everything back to the original version the problem disappeared, no MeasurementBrokerService is running anymore.



回答7:

The solution I found is to move the NotificationListenerService to it's own process. While having Google Play Services on another.

Background

First of all it is already a good decision to separate the NotificationListenerService, because this thing is running constantly after user grants the BIND_NOTIFICATION_LISTENER_SERVICE permission.

Basically unless declared otherwise, your app is going to use one process. This means that inside the "Running Services" tab in addition to all notification data stored in the NotificationListenerService you are going to see all your garbage that is yet to be collected by GC.

How to

In order to run a service in it's own process you need to add the android:process attribute in your Manifest.xml

<service android:name="com.mypackage.services.NotificationService"
android:label="@string/app_name"
android:process=":myawesomeprocess"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">

Things to remember

You can't communicate between processes in a regular way! You won't be able to access another Class from a Service that resides in it's own process. The only solution is to use Broadcasts

//Send
Intent intent = new Intent("com.mypackage.myaction");
context.sendBroadcast(intent);

//Receive
registerReceiver(broadcastReceiver, new IntentFilter("com.mypackage.myaction"));

BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action!=null&&action.equals("com.mypackage.myaction")) {
            //
        }
    }
};

//Don't forget to unregister
unregisterReceiver(broadcastReceiver);

Make sure you use context and not LocalBroadcastManager, cause it doesn't work with processes.