1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| import org.apache.tools.ant.taskdefs.condition.Os
def downloadUrl = Os.isFamily(Os.FAMILY_WINDOWS) ? rootProject.ext.jiagu["jiagubao_windows"] : rootProject.ext.jiagu["jiagubao_mac"]
def zipPath = rootProject.ext.jiagu["zipPath"] def unzipPath = rootProject.ext.jiagu["unzipPath"]
def APP1_OUTPUT_PATH = "jiagu/apk/app1/"
def APP1_APK_PATH = "${projectDir.absolutePath}/build/outputs/apk/app1Online/release/${getApkName(rootProject.ext.APP1_VERSION_NAME)}"
def jiaGu(String config, String apkPath, String outputPath, boolean automulpkg) { exec { executable = 'java' args = ['-jar', rootProject.ext.jiagu["jarPath"], '-login', rootProject.ext.jiagu["name"], rootProject.ext.jiagu["password"]] } exec { executable = 'java' args = ['-jar', rootProject.ext.jiagu["jarPath"], '-update'] } exec { executable = 'java' args = ['-jar', rootProject.ext.jiagu["jarPath"], '-version'] }
exec { executable = 'java' args = ['-jar', rootProject.ext.jiagu["jarPath"], '-importsign', rootProject.ext.signing["storeFile"], rootProject.ext.signing["storePassword"], rootProject.ext.signing["keyAlias"], rootProject.ext.signing["keyPassword"]] }
exec { executable = 'java' args = ['-jar', rootProject.ext.jiagu["jarPath"], '-config', config] }
def jiaGuArgs if (automulpkg) { jiaGuArgs = ['-jar', rootProject.ext.jiagu["jarPath"], '-jiagu', apkPath, outputPath, '-autosign', '-automulpkg', '-pkgparam', rootProject.ext.jiagu["channelConfigPath"] ] } else { jiaGuArgs = ['-jar', rootProject.ext.jiagu["jarPath"], '-jiagu', apkPath, outputPath, '-autosign' ] } exec { executable = 'java' args = jiaGuArgs } println "加固的文件路径:${apkPath}" println "加固后的文件路径:${outputPath}" }
task releaseApp1(dependsOn: 'assembleApp1OnlineRelease') { doFirst { File jarFile = file(rootProject.ext.jiagu["jarPath"]) if (!jarFile.exists()) { download360jiagu.execute() } } group = "publish" doLast { File apkOutputFile = new File(APP1_OUTPUT_PATH, getCurTime()) checkOutputDir(apkOutputFile) File apkFile = file(APP1_APK_PATH) if (!apkFile.exists()) { println("apk file is not exists:" + apkFile.absolutePath) return } jiaGu("-", apkFile.absolutePath, apkOutputFile.absolutePath, true) } }
private static void checkOutputDir(File apkOutputFile) { if (apkOutputFile.exists()) { File[] files = apkOutputFile.listFiles() if (files != null) { for (File file : files) { file.delete() } } } else { apkOutputFile.mkdirs() } }
static def getCurTime() { return new Date().format("yyyy-MM-dd HH:mm:ss") }
|