Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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

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

assembleDebug {}.doLast{
    tasks.copySupportFiles.execute()
}
like image 680
Harkish Avatar asked Aug 20 '15 02:08

Harkish


People also ask

How do I manually sync Gradle files?

Open your gradle. properties file in Android Studio. Restart Android Studio for your changes to take effect. Click Sync Project with Gradle Files to sync your project.

What is FileTree in Gradle?

A FileTree represents a hierarchy of files. It extends FileCollection to add hierarchy query and manipulation methods. You typically use a FileTree to represent files to copy or the contents of an archive. You can obtain a FileTree instance using Project.

What is a lifecycle task in Gradle?

In Gradle terms this means that you can define tasks and dependencies between tasks. Gradle guarantees that these tasks are executed in the order of their dependencies, and that each task is executed only once. These tasks form a Directed Acyclic Graph.


1 Answers

Your doLast should be placed in afterEvaluate:

afterEvaluate {
    assembleRelease.doLast {
        tasks.copySupportFiles.execute()
    }
}
like image 191
drakeet Avatar answered Sep 28 '22 12:09

drakeet