Gradle process manifest with new merge manifest

I am using this code to remove permission which I do not want in manifest file, however with new merge this is not possible and I don’t know how to do it, gradle to change 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 doesn't work

    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 this with a new merge?

Thansk in advance.

+3


source to share


2 answers


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')
        }
   }
}

      



It can help you easily.

+8


source


In order to answer my own question I ended up solving this problem by setting the TargeSdkVersion in the gradle file to a higher version than 15, that's why Android was adding permission to read the call log. Thus, there is no need to process the manifest and manually delete it.



0


source







All Articles