“Service MeasurementBrokerService is in use” is sh

2019-01-22 21:15发布

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.

enter image description here


Showing two processes hereenter image description here

7条回答
甜甜的少女心
2楼-- · 2019-01-22 21:36

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楼-- · 2019-01-22 21:38

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.

查看更多
叛逆
4楼-- · 2019-01-22 21:39

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.

查看更多
做个烂人
5楼-- · 2019-01-22 21:43

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/

查看更多
我只想做你的唯一
6楼-- · 2019-01-22 21:50

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

查看更多
可以哭但决不认输i
7楼-- · 2019-01-22 21:50

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.

查看更多
登录 后发表回答