gradle打包编译进程process获取信息

2024-05-30 10:08

本文主要是介绍gradle打包编译进程process获取信息,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

通过获取编译进程信息,获取添加log日志及记录编译时各个进程的信息。

调整打包apk名称

    applicationVariants.all { variant ->mavenFlavorName = variant.flavorNamevariant.outputs.all { output ->outputFileName = "${project.getName()}_${variant.flavorName}_${variant.buildType.name}_${variant.versionName}_${variant.versionCode}_${releaseTime()}.apk"}}
android.applicationVariants.all { variant ->variant.outputs.each { output ->def processManifest = output.getProcessManifestProvider().get()processManifest.doLast { task ->def outputDir = task.multiApkManifestOutputDirectoryFile outputDirectoryif (outputDir instanceof File) {outputDirectory = outputDir} else {outputDirectory = outputDir.get().asFile}File manifestOutFile = file("$outputDirectory/AndroidManifest.xml")println("----------- ${manifestOutFile} ----------- ")if (manifestOutFile.exists() && manifestOutFile.canRead() && manifestOutFile.canWrite()) {def manifestFile = manifestOutFile///这里第二个参数是 false ,所以 namespace 是展开的,所以下面不能用 androidSpace,而是用 nameTagdef xml = new XmlParser(false, false).parse(manifestFile)def exportedTag = "android:exported"def nameTag = "android:name"///指定 space//def androidSpace = new groovy.xml.Namespace('http://schemas.android.com/apk/res/android', 'android')def nodes = xml.application[0].'*'.findAll {//挑选要修改的节点,没有指定的 exported 的才需要增加//如果 exportedTag 拿不到可以尝试 it.attribute(androidSpace.exported)(it.name() == 'activity' || it.name() == 'receiver' || it.name() == 'service') && it.attribute(exportedTag) == null}///添加 exported,默认 falsenodes.each {def isMain = falseit.each {if (it.name() == "intent-filter") {it.each {if (it.name() == "action") {//如果 nameTag 拿不到可以尝试 it.attribute(androidSpace.name)if (it.attributes().get(nameTag) == "android.intent.action.MAIN") {isMain = trueprintln("......................MAIN FOUND......................")}}}}}it.attributes().put(exportedTag, "${isMain}")}PrintWriter pw = new PrintWriter(manifestFile)pw.write(groovy.xml.XmlUtil.serialize(xml))pw.close()}}}}
android.applicationVariants.all { variant ->variant.outputs.each { output ->//println("=============== ${variant.getBuildType().name.toUpperCase()} ===============")//println("=============== ${variant.getFlavorName()} ===============")def vnif (variant.getFlavorName() != null && variant.getFlavorName() != "") {vn = variant.name;} else {if (variant.getBuildType().name == "release") {vn = "Release"} else {vn = "Debug"}}def taskName = "process${vn}MainManifest";try {println("=============== taskName ${taskName} ===============")project.getTasks().getByName(taskName)} catch (Exception e) {return}///你的自定义名字project.getTasks().getByName(taskName).doFirst {//def method = it.getClass().getMethods()it.getManifests().getFiles().each {if (it.exists() && it.canRead()) {def manifestFile = itdef exportedTag = "android:exported"def nameTag = "android:name"///这里第二个参数是 false ,所以 namespace 是展开的,所以下面不能用 androidSpace,而是用 nameTagdef xml = new XmlParser(false, false).parse(manifestFile)if (xml.application != null && xml.application.size() > 0) {def nodes = xml.application[0].'*'.findAll {//挑选要修改的节点,没有指定的 exported 的才需要增加//如果 exportedTag 拿不到可以尝试 it.attribute(androidSpace.exported)(it.name() == 'activity' || it.name() == 'receiver' || it.name() == 'service') && it.attribute(exportedTag) == null}if (nodes.application != null && nodes.application.size() > 0) {nodes.each {def t = itit.each {if (it.name() == "intent-filter") {println("$manifestFile \n .....................${t.attributes().get(nameTag)}......................")}}}}}}}}}
}

这篇关于gradle打包编译进程process获取信息的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1016112

相关文章

Linux kill正在执行的后台任务 kill进程组使用详解

《Linuxkill正在执行的后台任务kill进程组使用详解》文章介绍了两个脚本的功能和区别,以及执行这些脚本时遇到的进程管理问题,通过查看进程树、使用`kill`命令和`lsof`命令,分析了子... 目录零. 用到的命令一. 待执行的脚本二. 执行含子进程的脚本,并kill2.1 进程查看2.2 遇到的

Python打包成exe常用的四种方法小结

《Python打包成exe常用的四种方法小结》本文主要介绍了Python打包成exe常用的四种方法,包括PyInstaller、cx_Freeze、Py2exe、Nuitka,文中通过示例代码介绍的非... 目录一.PyInstaller11.安装:2. PyInstaller常用参数下面是pyinstal

nodejs打包作为公共包使用的完整流程

《nodejs打包作为公共包使用的完整流程》在Node.js项目中,打包和部署是发布应用的关键步骤,:本文主要介绍nodejs打包作为公共包使用的相关资料,文中通过代码介绍的非常详细,需要的朋友可... 目录前言一、前置准备二、创建与编码三、一键构建四、本地“白嫖”测试(可选)五、发布公共包六、常见踩坑提醒

C#使用SendMessage实现进程间通信的示例代码

《C#使用SendMessage实现进程间通信的示例代码》在软件开发中,进程间通信(IPC)是关键技术之一,C#通过调用WindowsAPI的SendMessage函数实现这一功能,本文将通过实例介绍... 目录第一章:SendMessage的底层原理揭秘第二章:构建跨进程通信桥梁2.1 定义通信协议2.2

Vite 打包目录结构自定义配置小结

《Vite打包目录结构自定义配置小结》在Vite工程开发中,默认打包后的dist目录资源常集中在asset目录下,不利于资源管理,本文基于Rollup配置原理,本文就来介绍一下通过Vite配置自定义... 目录一、实现原理二、具体配置步骤1. 基础配置文件2. 配置说明(1)js 资源分离(2)非 JS 资

解决Nginx启动报错Job for nginx.service failed because the control process exited with error code问题

《解决Nginx启动报错Jobfornginx.servicefailedbecausethecontrolprocessexitedwitherrorcode问题》Nginx启... 目录一、报错如下二、解决原因三、解决方式总结一、报错如下Job for nginx.service failed bec

Linux系统管理与进程任务管理方式

《Linux系统管理与进程任务管理方式》本文系统讲解Linux管理核心技能,涵盖引导流程、服务控制(Systemd与GRUB2)、进程管理(前台/后台运行、工具使用)、计划任务(at/cron)及常用... 目录引言一、linux系统引导过程与服务控制1.1 系统引导的五个关键阶段1.2 GRUB2的进化优

idea Maven Springboot多模块项目打包时90%的问题及解决方案

《ideaMavenSpringboot多模块项目打包时90%的问题及解决方案》:本文主要介绍ideaMavenSpringboot多模块项目打包时90%的问题及解决方案,具有很好的参考价值,... 目录1. 前言2. 问题3. 解决办法4. jar 包冲突总结1. 前言之所以写这篇文章是因为在使用Mav

Go语言编译环境设置教程

《Go语言编译环境设置教程》Go语言支持高并发(goroutine)、自动垃圾回收,编译为跨平台二进制文件,云原生兼容且社区活跃,开发便捷,内置测试与vet工具辅助检测错误,依赖模块化管理,提升开发效... 目录Go语言优势下载 Go  配置编译环境配置 GOPROXYIDE 设置(VS Code)一些基本

一文解密Python进行监控进程的黑科技

《一文解密Python进行监控进程的黑科技》在计算机系统管理和应用性能优化中,监控进程的CPU、内存和IO使用率是非常重要的任务,下面我们就来讲讲如何Python写一个简单使用的监控进程的工具吧... 目录准备工作监控CPU使用率监控内存使用率监控IO使用率小工具代码整合在计算机系统管理和应用性能优化中,监