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

Android Gradle task to copy files after build

我正在尝试将几个文件从源代码树复制到 Gradle 最终生成 apk 文件的目录。构建似乎进展顺利,但我似乎没有看到副本工作。我在模块 build.gradle

中添加了以下任务
task copySupportFiles(type: Copy){
    from 'src/main/support'
    into 'build/outputs/apk'
    include '**/.dat'
    include '**/.txt'
}

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

正如@Steffen Funke 在评论中提到的,错误在额外的星号中:

'**/.dat'应该是'**/*.dat'

你的 doLast 应该放在 afterEvaluate:

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