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

相关文章

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使用率小工具代码整合在计算机系统管理和应用性能优化中,监

Linux进程CPU绑定优化与实践过程

《Linux进程CPU绑定优化与实践过程》Linux支持进程绑定至特定CPU核心,通过sched_setaffinity系统调用和taskset工具实现,优化缓存效率与上下文切换,提升多核计算性能,适... 目录1. 多核处理器及并行计算概念1.1 多核处理器架构概述1.2 并行计算的含义及重要性1.3 并

Linux下进程的CPU配置与线程绑定过程

《Linux下进程的CPU配置与线程绑定过程》本文介绍Linux系统中基于进程和线程的CPU配置方法,通过taskset命令和pthread库调整亲和力,将进程/线程绑定到特定CPU核心以优化资源分配... 目录1 基于进程的CPU配置1.1 对CPU亲和力的配置1.2 绑定进程到指定CPU核上运行2 基于

golang程序打包成脚本部署到Linux系统方式

《golang程序打包成脚本部署到Linux系统方式》Golang程序通过本地编译(设置GOOS为linux生成无后缀二进制文件),上传至Linux服务器后赋权执行,使用nohup命令实现后台运行,完... 目录本地编译golang程序上传Golang二进制文件到linux服务器总结本地编译Golang程序

java使用protobuf-maven-plugin的插件编译proto文件详解

《java使用protobuf-maven-plugin的插件编译proto文件详解》:本文主要介绍java使用protobuf-maven-plugin的插件编译proto文件,具有很好的参考价... 目录protobuf文件作为数据传输和存储的协议主要介绍在Java使用maven编译proto文件的插件