美文网首页
记如何快速给所有activity添加screenOrientat

记如何快速给所有activity添加screenOrientat

作者: 共产主义接班ren | 来源:发表于2019-08-29 14:08 被阅读0次

    android.applicationVariants.all { variant ->

    variant.outputs.all { output ->

    output.processManifest.doLast {

    // Stores the path to the maifest.

                println'xxx'+manifestOutputDirectory

    String manifestPath ="/Users/mac/workspace/demo/PlugDemo/app/build/intermediates/merged_manifests/debug/AndroidManifest.xml"

                def manifestContent = file(manifestPath).getText()

    def xml =new XmlParser().parseText(manifestContent)

    def activitys = xml.application[0].activity

    activitys.each { activity ->

    def attrs = activity.attributes()

    def isAddScreenOrientation =false

                        attrs.each { attr ->

    String key = attr.getKey()

    if ('{http://schemas.android.com/apk/res/android}screenOrientation'.equals(key)) {

    isAddScreenOrientation =true

                            }

    }

    if (!isAddScreenOrientation) {

    attrs.put('android:screenOrientation','portrait')

    }

    }

    def serialize = groovy.xml.XmlUtil.serialize(xml)

    file(manifestPath).write(serialize)

    }

    }

    }

    其中String manifestPath ="/Users/mac/workspace/demo/PlugDemo/app/build/intermediates/merged_manifests/debug/AndroidManifest.xml"是动态的但是我实在是不知道该咋给只好通过

    来获取值 一定要记得根据自己的需求改哦 这是我们在项目中的manfiest 这是apk里面生成的

    最后记住啊gradle3.0以上才阔以哦

    实在是不会排版就这凑活看吧

    相关文章

      网友评论

          本文标题:记如何快速给所有activity添加screenOrientat

          本文链接:https://www.haomeiwen.com/subject/khavgxtx.html