Grishka Grishka - 2 months ago 13x
Android Question

Android manifest merger silently adds permissions

My Gradle project contains 4 libraries. In recent builds of my app I found that Android Studio is silently adding "read call log" and "write call log" permissions to the manifest. In the build folder is a "final" manifest that is packaged into the apk and it contains these 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 either disable this weird behavior completely or enable some logging to know where this comes from? I don't like when software tries to be smarter than me.


The manifests are merged, so this is not supported yet.

You can archieve this by adding a new gradle task to your build.gradle, and attaching it as a dependence of 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("")

tasks.whenTaskAdded { task ->
    if( == 'processDebugResources'){
        task.dependsOn 'removeExtraPermissionsDebug'

If you have custom flavours and build types, take into account the names of the tasks you need to attach to: process{Flavour}{BuildType}Resources.
You may need to replicate the task to delete permissions also when generating the release.