Android Wear new (unwanted) permissions

2019-06-03 10:10发布

问题:

I recently switched from API 21 to 23 to create Android Wear watch faces.
In the interest of brevity I will not comment on the excruciating process. (1)

As I was uploading to Google Play I noticed that the new API has added, without my consent, 4 new rights:

    Required permissions 6 permissions (4 added)
=>    android.permission.ACCESS_NETWORK_STATE
=>    android.permission.INTERNET
    android.permission.WAKE_LOCK
=>    com.google.android.c2dm.permission.RECEIVE
    com.google.android.permission.PROVIDE_BACKGROUND
=>    com.mycompany.mypackage.permission.C2D_MESSAGE

I double checked the manifest which contain my "usual"

<uses-permission android:name="com.google.android.permission.PROVIDE_BACKGROUND" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

How (the heck) do I get rid of these?


(1) Rarely an API made me want to punch someone square in the face so much.

回答1:

The extra permissions are probably being added by some part of Google Play Services - and which probably doesn't need them for what you're doing.

Solution #1 is to only use the pieces of Google Play Services that you actually need. In your Wear module's build.gradle file, you might have an entry that looks like this:

dependencies {
    compile com.google.android.gms:play-service:8.4.0
}

However, that will bring in the entire Play Services library - which requires a number of extra permissions. It might well be that all you need is this:

    compile com.google.android.gms:play-services-wearable:8.4.0

...or perhaps other specific modules. But the point is, don't include more than you need.

If you've pared the dependencies back as far as you can, and you're still getting extra permissions in your merged manifest, then you may need Solution #2 - which I described in detail in a different answer: https://stackoverflow.com/a/31017339/252080

Make sure you read all the way to the bottom, because there are some important caveats.