Sergio Serra
Sergio Serra

Reputation: 1479

Gradle process manifest with new Manifest Merger

I've been using this code to remove a permission i dont want from Manifest file, however with the new Merger this is not possible anymore and i don´t have the knowledge with gradle to modify it.

applicationVariants.all { variant ->
        variant.processManifest.doLast {
            println("configuring AndroidManifest.xml removing READ_CALL_LOG");

            def manifestFile = new File("${buildDir}/intermediates/manifests/${variant.dirName}/AndroidManifest.xml")
            def content = manifestFile.getText()
            def updatedContent = content.replaceAll("<android:uses-permission android:name=\"android.permission.READ_CALL_LOG\" />", "")
            manifestFile.write(updatedContent)
        }
        variant.processResources.manifestFile = new File("${buildDir}/intermediates/manifests/${variant.dirName}/AndroidManifest.xml")

}

I tried something like this but it's not working

    applicationVariants.all { variant ->
        variant.outputs.each { output ->
                def manifestOutFile = output.processManifest.manifestOutputFile
                def newFileContents = manifestOutFile.getText('UTF-8').replace("<android:uses-permission android:name=\"android.permission.READ_CALL_LOG\" />", "")
                manifestOutFile.write(newFileContents, 'UTF-8')
            }
       }

How can i achieve the same with the new Merger ?

Thansk in advance.

Upvotes: 3

Views: 2409

Answers (2)

vfs1234
vfs1234

Reputation: 141

applicationVariants.all { variant ->
    variant.outputs.each { output ->
           output.processManifest.doLast{
            def manifestOutFile = output.processManifest.manifestOutputFile
            def newFileContents = manifestOutFile.getText('UTF-8').replace("<android:uses-permission android:name=\"android.permission.READ_CALL_LOG\" />", "")
            manifestOutFile.write(newFileContents, 'UTF-8')
        }
   }
}

This could help you easily.

Upvotes: 8

Sergio Serra
Sergio Serra

Reputation: 1479

To answer my own question i ended up solving the problem by setting the TargeSdkVersion in gradle file to a higher version than 15, that's why Android was adding the Read Call Log permission. This way there's no need to process the manifest and remove it by hand.

Upvotes: 0

Related Questions