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()
}
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.
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.
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.
Your doLast
should be placed in afterEvaluate
:
afterEvaluate {
assembleRelease.doLast {
tasks.copySupportFiles.execute()
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With