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

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

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容