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

相关文章

Java进程CPU使用率过高排查步骤详细讲解

《Java进程CPU使用率过高排查步骤详细讲解》:本文主要介绍Java进程CPU使用率过高排查的相关资料,针对Java进程CPU使用率高的问题,我们可以遵循以下步骤进行排查和优化,文中通过代码介绍... 目录前言一、初步定位问题1.1 确认进程状态1.2 确定Java进程ID1.3 快速生成线程堆栈二、分析

Python程序打包exe,单文件和多文件方式

《Python程序打包exe,单文件和多文件方式》:本文主要介绍Python程序打包exe,单文件和多文件方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录python 脚本打成exe文件安装Pyinstaller准备一个ico图标打包方式一(适用于文件较少的程

Maven项目打包时添加本地Jar包的操作步骤

《Maven项目打包时添加本地Jar包的操作步骤》在Maven项目开发中,我们经常会遇到需要引入本地Jar包的场景,比如使用未发布到中央仓库的第三方库或者处理版本冲突的依赖项,本文将详细介绍如何通过M... 目录一、适用场景说明​二、核心操作命令​1. 命令格式解析​2. 实战案例演示​三、项目配置步骤​1

Python多进程、多线程、协程典型示例解析(最新推荐)

《Python多进程、多线程、协程典型示例解析(最新推荐)》:本文主要介绍Python多进程、多线程、协程典型示例解析(最新推荐),本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定... 目录一、multiprocessing(多进程)1. 模块简介2. 案例详解:并行计算平方和3. 实现逻

C#通过进程调用外部应用的实现示例

《C#通过进程调用外部应用的实现示例》本文主要介绍了C#通过进程调用外部应用的实现示例,以WINFORM应用程序为例,在C#应用程序中调用PYTHON程序,具有一定的参考价值,感兴趣的可以了解一下... 目录窗口程序类进程信息类 系统设置类 以WINFORM应用程序为例,在C#应用程序中调用python程序

Spring Boot项目打包和运行的操作方法

《SpringBoot项目打包和运行的操作方法》SpringBoot应用内嵌了Web服务器,所以基于SpringBoot开发的web应用也可以独立运行,无须部署到其他Web服务器中,下面以打包dem... 目录一、打包为JAR包并运行1.打包为可执行的 JAR 包2.运行 JAR 包二、打包为WAR包并运行

Python将字库文件打包成可执行文件的常见方法

《Python将字库文件打包成可执行文件的常见方法》在Python打包时,如果你想将字库文件一起打包成一个可执行文件,有几种常见的方法,具体取决于你使用的打包工具,下面就跟随小编一起了解下具体的实现方... 目录使用 PyInstaller基本方法 - 使用 --add-data 参数使用 spec 文件(

Android NDK版本迭代与FFmpeg交叉编译完全指南

《AndroidNDK版本迭代与FFmpeg交叉编译完全指南》在Android开发中,使用NDK进行原生代码开发是一项常见需求,特别是当我们需要集成FFmpeg这样的多媒体处理库时,本文将深入分析A... 目录一、android NDK版本迭代分界线二、FFmpeg交叉编译关键注意事项三、完整编译脚本示例四

Gradle在国内配置镜像加速的实现步骤

《Gradle在国内配置镜像加速的实现步骤》在国内使用Gradle构建项目时,最大的痛点就是依赖下载贼慢,甚至卡死,下面教你如何配置国内镜像加速Gradle下载依赖,主要是通过改写repositori... 目录引言一、修改 build.gradle 或 settings.gradle 的 reposito

Gradle下如何搭建SpringCloud分布式环境

《Gradle下如何搭建SpringCloud分布式环境》:本文主要介绍Gradle下如何搭建SpringCloud分布式环境问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录Gradle下搭建SpringCloud分布式环境1.idea配置好gradle2.创建一个空的gr