如何添加gradle复制任务

时间:2019-04-10 07:18:36

标签: android gradle

如何添加gradle任务以将文件从路径复制到另一个路径,例如:

subModulName\build\generated\source\debug\com\name\pc

在构建时创建此目录:

mainModulesub\build\generated\source\debug\com\name\pc

2 个答案:

答案 0 :(得分:0)

将波纹管任务添加到root gradle(顶层)

<ng-template #t let-fill="fill" let-index="index">
  <span class="star" [class.full]="fill === 100" [class.green]="index === 4" [class.orange]="index === 3">
    <i class="fas fa-square square-star"></i>
  </span>
</ng-template>

使用命令行(在根项目或android studio终端中)运行此任务:

task copyApk(type: Copy) {
    from "app/build/outputs/apk/release/"
    into "app/build/"
    rename "app-release.apk", "yourAppName-release.apk"
}

答案 1 :(得分:0)

尝试以下脚本,它还会在apk名称中附加日期

task copyFile(type: Copy) {
    def date = new Date()
    def formattedDate = date.format('yyyyMMdd')
    from('PATH_WHERE_YOUR_APK_IS_PRESENT')
    include('PATH_WHERE_WHERE_TO_COPY_APK')
    rename ('app-release.apk', 'app-release'+formattedDate+'.APK')
    into('release/')