Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
640 views
in Technique[技术] by (71.8m points)

android - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...