From 5125ea2edaf3ba29f060c6b98b416f4940f244b7 Mon Sep 17 00:00:00 2001 From: pppscn <35696959@qq.com> Date: Sun, 10 Mar 2024 19:22:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A`build.gradle`?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=EF=BC=8C=E7=BC=96=E8=AF=91=E5=89=8D=E5=90=8E?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 48 ++++++++++++++++++++++++++++++------------------ build.gradle | 28 +--------------------------- 2 files changed, 31 insertions(+), 45 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 45f8dd83..ec6fd19c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,3 @@ -//file:noinspection GrDeprecatedAPIUsage //file:noinspection DependencyNotationArgument import groovy.json.JsonBuilder import groovy.json.JsonSlurper @@ -24,7 +23,6 @@ if (isNeedPackage.toBoolean() && isUseBooster.toBoolean()) { } android { - //noinspection GradleDependency buildToolsVersion build_versions.build_tools compileSdkVersion build_versions.target_sdk @@ -88,8 +86,6 @@ android { // 调试模式开关 debuggable false jniDebuggable false - // 压缩对齐开关 - zipAlignEnabled true // 移除无用的资源 shrinkResources true // 代码混淆开关 @@ -119,8 +115,6 @@ android { // 调试模式开关 debuggable true jniDebuggable true - // 压缩对齐开关 - zipAlignEnabled true // 移除无用的资源 shrinkResources true // 代码混淆开关 @@ -174,21 +168,24 @@ android { } android.applicationVariants.configureEach { variant -> - // Assigns a different version code for each output APK. variant.outputs.each { output -> + //noinspection GrDeprecatedAPIUsage def abiName = output.getFilter(com.android.build.OutputFile.ABI) if (abiName == null) abiName = "universal" output.versionCodeOverride = abiCodes.get(abiName, 0) * 100000 + variant.versionCode output.outputFileName = "SmsF_${versionName}_${output.versionCode}_${abiName}_${variant.name}.apk" // 修改 output-metadata.json 追加编译日期、编译时间、Git Commit ID - variant.assemble.doLast { - def metadataFile = file("${variant.outputs[0].outputFile.parent}/output-metadata.json") - def metadata = new JsonSlurper().parseText(metadataFile.text) - metadata.buildDate = buildDate - metadata.buildTime = buildTime - metadata.gitCommitId = gitCommitId - metadataFile.text = new JsonBuilder(metadata).toPrettyString() + def assembleTaskName = "assemble${variant.name.capitalize()}" + tasks.named(assembleTaskName) { + doLast { + def metadataFile = file("${output.outputFile.parent}/output-metadata.json") + def metadata = new JsonSlurper().parseText(metadataFile.text) + metadata.buildDate = buildDate + metadata.buildTime = buildTime + metadata.gitCommitId = gitCommitId + metadataFile.text = new JsonBuilder(metadata).toPrettyString() + } } } } @@ -209,6 +206,23 @@ android { } namespace 'com.idormy.sms.forwarder' + //编译前清理项目缓存 + preBuild.dependsOn clean + //编译后清理垃圾文件 + gradle.buildFinished { buildResult -> + if (buildResult.failure == null) { + println "Build succeeded, cleaning text files..." + //delete rootProject.buildDir + FileTree rootTree = fileTree(dir: rootDir) + rootTree.each { File file -> + if ((file.toString().contains("ajcore") || file.toString().contains("mapping") || file.toString().contains("seeds") || file.toString().contains("unused")) && file.toString().endsWith(".txt")) { + delete file + } + } + } else { + println "Build failed, cleanTxt not executed." + } + } } dependencies { @@ -216,10 +230,8 @@ dependencies { //frpc implementation files('libs/frpclib.aar') - //kmnkt基于Kotlin Multiplatform的跨平台socket通信统一接口,支持UDP/TCP/MQTT协议 - //https://github.com/xuankaicat/kmnkt + //MQTT协议 implementation("org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5") - //implementation files('libs/socket-2.0.0-alpha06-2.aar') testImplementation deps.junit androidTestImplementation 'androidx.test.ext:junit:1.1.5' @@ -248,7 +260,7 @@ dependencies { implementation 'com.github.xuexiangjys.AgentWeb:agentweb-download:1.0.0'//选填 //屏幕适配AutoSize:https://github.com/JessYanCoding/AndroidAutoSize implementation 'me.jessyan:autosize:1.2.1' - //umeng统计 + //友盟统计 implementation 'com.umeng.umsdk:common:9.6.7' implementation 'com.umeng.umsdk:asms:1.8.2' diff --git a/build.gradle b/build.gradle index 525d3e1f..70080a7f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,3 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. //file:noinspection DependencyNotationArgument buildscript { @@ -22,10 +21,6 @@ buildscript { } } -//allprojects { -// addRepos(repositories) -//} - allprojects { repositories { google() @@ -38,31 +33,10 @@ allprojects { maven { url "https://jitpack.io" } } - // 设置全局编码 - tasks.withType(JavaCompile).configureEach { - options.encoding = 'UTF-8' - } - - // 设置文档编码 - tasks.withType(Javadoc).configureEach { - options { - encoding 'UTF-8' - charSet 'UTF-8' - links 'http://docs.oracle.com/javase/7/docs/api' - } - } - // 将构建文件统一输出到项目根目录下的 build 文件夹 setBuildDir(new File(rootDir, "build/${path.replaceAll(':', '/')}")) } tasks.register('clean', Delete) { delete rootProject.buildDir - - FileTree rootTree = fileTree(dir: rootDir) - rootTree.each { File file -> - if ((file.toString().contains("ajcore") || file.toString().contains("mapping") || file.toString().contains("seeds") || file.toString().contains("unused")) && file.toString().endsWith(".txt")) { - delete file - } - } -} +} \ No newline at end of file