Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Manifest Duplicate Permissions

We have an app that consists of a third party library (altbeacon), a locally built Android library and an app component. All three components have an AndroidManifest.xml which are merged during the build. The app is built using gradle.

THis app has been long published on the Google Play Store. In the last iteration we upgraded from API level 22 to 25. Everything built without error, the APK was installed on and tested on real devices without error, but when we came to update the app on Google Play, the upload of the APK failed with the error:

Upload failed
Duplicate declarations of permission android.permission.ACCESS_COARSE_LOCATION with different maxSdkVersions.

Anaylyzing the AndroidManaifest.xml we found org.altbeacon.beacon has the following permission:

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="23" />
<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION" />

Our local Android library module the targetSdkVersion is set to 25 in build.gradle and the the AndroidManifest.xml contains:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

In the app module the targetSdkVersion is set to 25 in build.gradle.

The generated AndroidManifest.xml in the app module contains:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION" />

and just to confirm, looking in the APK itself and extracting the binary manifest:

~/.android-sdk/build-tools/25.0.3/aapt l -a app-release.apk | grep -B1 COARSE
    E: uses-permission (line=62)
      A: android:name(0x01010003)="android.permission.ACCESS_COARSE_LOCATION" (Raw: "android.permission.ACCESS_COARSE_LOCATION")
--
    E: uses-permission-sdk-23 (line=76)
      A: android:name(0x01010003)="android.permission.ACCESS_COARSE_LOCATION" (Raw: "android.permission.ACCESS_COARSE_LOCATION")

So there is a duplicate tag, and I think the manifest merger should have recognized that and removed the one from the altbeacon library. My question is how do I remove the permission from the altbeacon library?

I have tried the following in the app module AndroidManifest.xml:

<uses-permission-sdk-23
   android:name="android.permission.ACCESS_COARSE_LOCATION"
   tools:node="remove"
   tools:selector="org.altbeacon.beacon"/>

This results in:

AndroidManifest.xml:12:5-15:48 Warning:
        uses-permission-sdk-23 was tagged at AndroidManifest.xml:12 to remove other declarations but no other declaration present

and

<uses-permission
   android:name="android.permission.ACCESS_COARSE_LOCATION"
   tools:node="remove"
   tools:selector="org.altbeacon.beacon"/>

This results in:

AndroidManifest.xml:12:5-15:48 Warning:
        uses-permission was tagged at AndroidManifest.xml:12 to remove other declarations but no other declaration present

The following does work, but it removes the wrong tag, it removes the one in the local Android library we build as part of our app.

 <uses-permission
      android:name="android.permission.ACCESS_COARSE_LOCATION"
      tools:node="remove"/>

The org.altbeacon.beacon permission is left:

~/.android-sdk/build-tools/25.0.3/aapt l -a app-release.apk | grep -B1 COARSE
E: uses-permission-sdk-23 (line=72)
  A: android:name(0x01010003)="android.permission.ACCESS_COARSE_LOCATION" (Raw: "android.permission.ACCESS_COARSE_LOCATION")

Which is unsatisfying because if the permission in org.altbeacon.beacon library chamge, or it is removed in the future, the ACCESS_COARSE_PERMISSION will be missing from our app.

Any suggestions on how to fix this properly?

like image 530
BitByteDog Avatar asked Jun 01 '17 05:06

BitByteDog


People also ask

How do I declare permissions in Android manifest?

Add declaration to app manifest To declare a permission that your app might request, include the appropriate <uses-permission> element in your app's manifest file. For example, an app that needs to access the camera has this line in AndroidManifest. xml : <manifest ...>

What is manifest permission in Android?

Manifest. permission . The name of the permission. It can be a permission defined by the application with the <permission> element, a permission defined by another application, or one of the standard system permissions (such as "android.

How can you tell if a manifest is merged?

Even before you build your app, you can see a preview of what your merged manifest looks by opening your AndroidManifest. xml file in Android Studio, and then clicking the Merged Manifest tab at the bottom of the editor.

What is manifestPlaceholders?

However, Android toolchain provides customization by allowing you to specify dynamic information through variable declaration, generally referred as Android Manifest placeholders. These variables are specified under the manifestPlaceholders block in your build. gradle file.


2 Answers

In your App manifest file add the below merge rule.

<uses-permission-sdk-23
        tools:node="removeAll" />

Make sure you already added the location permission.

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
like image 123
jibysthomas Avatar answered Sep 17 '22 22:09

jibysthomas


Just replace below line to your existing uses permission would solve the issues.

What this causes because you added duplicated permission in manifest but below line split the permission.

<uses-permission
      android:name="android.permission.ACCESS_COARSE_LOCATION"
      android:maxSdkVersion="22"/>
like image 20
liccowee Avatar answered Sep 20 '22 22:09

liccowee