AndroidStudio2021/3版 gradle7.0環境 自定義輸出apk路徑


在moudle中的build.gradle

android {
  ...
  //修改輸出的APK路徑
    applicationVariants.all { variant ->
        // 打包完成后復制到的目錄
        def outputFileDir = "${project.projectDir.absolutePath}/apk/${variant.buildType.name}/${variant.versionName}"
        //確定輸出文件名
        def today = new Date()
        def path = ((project.name != "app") ? project.name : rootProject.name.replace(" ", "")) + "_" +
                variant.flavorName + "_" +
                variant.buildType.name + "_" +
                variant.versionName + "_" +
                today.format('yyyyMMddhhmm') +
                ".apk"
        variant.outputs.forEach {
            it.outputFileName = path
        }
        // 打包完成后做的一些事,復制apk到指定文件夾
        variant.assemble.doLast {
            File out = new File(outputFileDir)
            copy {
                variant.outputs.forEach { file ->
                    copy {
                        from file.outputFile
                        into out
                    }
                }
            }
        }
    }        
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM