android build.dolast,android - gradle copy as doLast not working - Stack Overflow

I am trying to do a very simple thing. As gradle removes all files in the build dir when cleaning I want to move the apks somewhere else when creating release versions. So I added a copy task into the chain and I set it to be the last. Anything I tried did't work. So I simplified it and added some logging to make a point. I think it just doesn't work.

Using two variables, I can check that at task definition time and execution time the input and output paths are valid. I can also check that the task is executed. I put some more files in the input directory to make sure there is also something there in any case. This is the script:

def buildPath

def outPath

task copyApks(type: Copy) {

buildPath = "$buildDir\\outputs\\apk"

outPath ="$buildDir\\outputs\\apk2"

logger.error("Source Folder is $buildPath")

logger.error("Destination Folder is $outPath")

from buildPath

into outPath

}

assembleRelease.doLast {

android.applicationVariants.all { variant ->

println "Variant $variant.name"

logger.error("Source Folder is $buildPath")

logger.error("Destination Folder is $outPath")

copyApks

}

}

And this is the output, where one can see that the paths are correct (they exist and are valid) both at definition and execution time. Also one can see that the task is executed:

What is wrong?

Executing external task 'assembleRelease'...

Parallel execution with configuration on demand is an incubating feature.

Source Folder is C:\Users\Administrator\Projects\Gradle\MB6\app\build\outputs\apk

Destination Folder is C:\Users\Administrator\Projects\Gradle\MB6\app\build\outputs\apk2

................

some other gradle logs

................

:app:assembleRelease

Variant debug

Source Folder is C:\Users\Administrator\Projects\Gradle\MB6\app\build\outputs\apk

Destination Folder is C:\Users\Administrator\Projects\Gradle\MB6\app\build\outputs\apk2

Variant release

Source Folder is C:\Users\Administrator\Projects\Gradle\MB6\app\build\outputs\apk

Destination Folder is C:\Users\Administrator\Projects\Gradle\MB6\app\build\outputs\apk2

BUILD SUCCESSFUL

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值