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

2019-08-29  本文已影响0人  共产主义接班ren

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以上才阔以哦

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

上一篇下一篇

猜你喜欢

热点阅读