Change the output name to save the output file path
Def fileArray = [] / / traverse the output file android applicationVariants. All {variant - > the variant. The outputs. All {output - > def outputFile = output.outputFileif(outputFile ! = null && outputFile.name.endsWith('release.apk')) {
def fileName = "xxx_${defaultConfig.versionName}_${defaultConfig.versionCode}" +
"_${variant.productFlavors[0].name}.apk"OutputFileName = fileName / / added to the array output File path fileArray. Add (outputFile. ParentFile. AbsolutePath + File. The separator + fileName)} }Copy the code
AssembleRelease is an assembleRelease command that only builds the release version of the package
The build {//build command adds this codedoLast() {// walk through the array of files and operateforAfterEvaluate {assemblerelease. doLast {assembleRelease {assembleRelease {assembleRelease {assembleRelease}forEachFile(fileArray)
}
}
def forRename_andd_moveout_apk (file)} EachFile(fileArray) {filearray.foreach {file -> rename_andd_moveout_apk(file)}Copy the code
} You can use copy rename to perform file operations
def rename_andd_moveout_apk(orignalFile) {
def intoFile = rootDir.parentFile.getAbsolutePath()+File.separator+"apk"
copy {
from orignalFile
into intoCodeFile
rename("${android.defaultConfig.versionName}_
${android.defaultConfig.versionCode}_"."")}}Copy the code
You can use gradle scripts to dynamically configure some third-party configurations in Mainfest. This allows you to switch between DEV and PRD environments: Android. DefaultConfig. ManifestPlaceholders = [” key “:” value “] in the Mainfest use ${key} reference you want to use third-party configuration data, the development process is usually applied to push, ring letter environment configuration
There are mistakes, I hope you correct! t.cn/Rlvl2Zu