Android manifest merge silently adds permissions

My Gradle project contains 4 libraries. In the latest builds of my application, I found that Android Studio silently adds permissions to “read call log” and “record call log” to the manifest. In the build folder is the "final" manifest, which is packaged in apk and contains the following lines:

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

Is there a way to completely disable this strange behavior or to let some magazines know where it came from? I don't like it when software tries to be smarter than me.

+5
source share
2 answers

You can use Combine Conflict Markers "to remove this tag from your Android manifest.

Then you can configure the following code on your AndroidManifest, and they will be deleted:

 <uses-permission android:name="android.permission.READ_CALL_LOG" tools:node="remove"/> <uses-permission android:name="android.permission.WRITE_CALL_LOG" tools:node="remove"/> 
+7
source

manifest are merged, so this is not yet supported.

You can archive this by adding a new gradle task to your build.gradle and linking it as a dependency of the processDebugResources and processReleaseResources gradle tasks.

 task('removeExtraPermissionsDebug') << { //Input the correct manifest file (could be under 'full' folder). def manifestFile = file("build/intermediates/manifests/full/debug/AndroidManifest.xml") def patternPermissions = Pattern.compile(".+(android\\.permission\\.ACCESS_NETWORK_STATE|android\\.permission\\.WAKE_LOCK).+") def manifestText = manifestFile.getText() def matcherPermissions = patternPermissions.matcher(manifestText) def newManifestText = matcherPermissions.replaceAll("") manifestFile.write(newManifestText) } tasks.whenTaskAdded { task -> if(task.name == 'processDebugResources'){ task.dependsOn 'removeExtraPermissionsDebug' } } 

Notes:
If you have custom tastes and build types, consider the names of the tasks you need to attach: process{Flavour}{BuildType}Resources .
You may need to replicate the task to remove permissions when creating the release.

0
source

Source: https://habr.com/ru/post/1206369/


All Articles