ソースを参照

feat: Jenkins构建(产物目录/archive)

DoggyZhang 20 時間 前
コミット
a55255b5da
2 ファイル変更33 行追加3 行削除
  1. 2 1
      .gitignore
  2. 31 2
      app/build.gradle

+ 2 - 1
.gitignore

@@ -21,4 +21,5 @@ schemas/
 schemas/*
 app/release/
 app/gami/release
-/tool/log/config.ini
+/tool/log/config.ini
+/archive

+ 31 - 2
app/build.gradle

@@ -306,15 +306,20 @@ gradle.taskGraph.addTaskExecutionListener(new TaskExecutionListener() {
 
             println("afterExecute " + task.name)
             def aabDir = project.getBuildDir().absolutePath + '/outputs/bundle'
+            def archiveDir = rootProject.file("archive")
+            def buildNumber = System.getenv("BUILD_NUMBER") ?: "local"
+            def targetDir = new File(archiveDir, buildNumber)
+            
             fileTree(dir: aabDir, include: '*/*.aab').each { File file ->
                 println(file.absolutePath)
+                def apksPath = file.parent + File.separator + file.name.replace(".aab", "-split.apks")
                 def cmd = []
                 cmd << "java"
                 cmd << "-jar"
                 cmd << "${project.rootDir}/tool/bundletool.jar"
                 cmd << "build-apks"
                 cmd << "--bundle=" + file.absolutePath
-                cmd << "--output=" + file.parent + File.separator + file.name.replace(".aab", "-split.apks")
+                cmd << "--output=" + apksPath
                 cmd << "--overwrite"
                 cmd << "--mode=universal"
                 if (task.name.equalsIgnoreCase("bundleDebug")) {
@@ -334,8 +339,32 @@ gradle.taskGraph.addTaskExecutionListener(new TaskExecutionListener() {
                 exec {
                     commandLine cmd
                 }
+                
+                println("extracting apks: " + apksPath)
+                def outputDir = file.parent + File.separator + file.name.replace(".aab", "-extracted")
+                project.copy {
+                    from project.zipTree(apksPath)
+                    into outputDir
+                }
+
+                // 1. 重命名 universal.apk 为 apks 的名称 (xxx-split.apk)
+                def apksFile = new File(apksPath)
+                def finalApkName = apksFile.name.replace(".apks", ".apk")
+                def finalApkFile = new File(file.parentFile, finalApkName)
+                def extractedApk = new File(outputDir, "universal.apk")
+                if (extractedApk.exists()) {
+                    extractedApk.renameTo(finalApkFile)
+                }
+
+                // 2. 复制 APK 和 AAB 到 archive 目录下
+                println("archiving to: " + targetDir.absolutePath)
+                project.copy {
+                    from file
+                    from finalApkFile
+                    into targetDir
+                }
             }
-            println("after build apks")
+            println("after build, extract and archive")
         }
     }
 })