简体   繁体   English

Android Gradle任务在构建后复制文件

[英]Android Gradle task to copy files after build

I am trying to copy a couple of files from the source tree to the directory where Gradle finally generates the apk files. 我试图将源文件中的几个文件复制到Gradle最终生成apk文件的目录中。 The build seems to go fine but I do not seem to see the copy working. 构建似乎很好,但我似乎没有看到副本工作。 I added the following task in my modules build.gradle 我在我的模块build.gradle中添加了以下任务

task copySupportFiles(type: Copy){
    from 'src/main/support'
    into 'build/outputs/apk'
    include '**/.dat'
    include '**/.txt'
}

assembleDebug {}.doLast{
    tasks.copySupportFiles.execute()
}

As mentioned by @Steffen Funke in comments the error is in the additional asterisk : 正如@Steffen Funke在评论中提到的那样,错误在附加的星号中:

'**/.dat' should be '**/*.dat' '**/.dat'应为'**/*.dat'

Your doLast should be placed in afterEvaluate : 你的doLast应放在afterEvaluate

afterEvaluate {
    assembleRelease.doLast {
        tasks.copySupportFiles.execute()
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM