I have gradle task which unbacks lib-debug.aar
need execute this task after crate this lib-debug.aar file
task unzip<<{
copy {
def aarFile = file("${buildDir}/outputs/aar/lib-debug.aar")
def outputDir = file("${buildDir}/outputs/eclipse")
from zipTree(aarFile)
into outputDir
}
You can just do:
unzip.dependsOn assemble
That will make it so that whenever you run the unzip task, the assemble task has to have run before.
Related
1. Summary
I am having an problem. 1 of my custom tasks running depended on each other is having difficulties extracting
tar.gz
files. Thus failing entire build.
I want to achieve extraction of those tars, but as it can be experienced result is not correct.
Output from Console:
> Task :app:ndkBuilds FAILED
Android NDK: Your APP_BUILD_SCRIPT points to an unknown file: SDL-release-2.0.20/Android.mk
/home/rafal/AndroidSDK/ndk/21.4.7075529/build/core/add-application.mk:88: *** Android NDK: Aborting... . Stop.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:ndkBuilds'.
> Process 'command '/home/rafal/AndroidSDK/ndk/21.4.7075529/ndk-build'' finished with non-zero exit value 2
The cultplit task here:
extractArchives()
Code of that particular task is at bottom.
2. What have been done so far
I have tried to use
doFirts {}
Also did noticed when running a build 2nd time without cleaning. It does extract and script proceed to the next task.
3. Code
Here is entire code:
task downloadFiles(type: Download) {
src([
'https://github.com/libsdl-org/SDL/archive/release-2.0.20.tar.gz',
'https://github.com/openssl/openssl/archive/OpenSSL_1_1_1l.tar.gz',
'https://github.com/curl/curl/archive/curl-7_80_0.tar.gz'
])
dest "${buildDir}"
overwrite false
}
task extractArchives() {
dependsOn downloadFiles
fileTree("${buildDir}").matching {
include "*.tar.gz"
}.visit {
FileVisitDetails details -> exec {
commandLine ('tar', '-zxf', "${details.file.path}")
}
}
}
task ndkBuilds(type: Exec) {
dependsOn extractArchives
def ndkDir = android.ndkDirectory
executable = "$ndkDir/ndk-build"
args = ['NDK_PROJECT_PATH=build/intermediates/ndk',
'NDK_LIBS_OUT=src/main/jniLibs',
'APP_ABI := armeabi-v7a arm64-v8a',
'APP_PLATFORM=android-21',
'APP_BUILD_SCRIPT=SDL-release-2.0.20/Android.mk']
}
gradle.taskGraph.whenReady { graph ->
if (graph.hasTask(clean)) {
downloadFiles.enabled = false
extractArchives.enabled = false
ndkBuilds.enabled = false
}
}
//extractArchives.dependsOn downloadFiles
//ndkBuilds.dependsOn extractArchives
preBuild.dependsOn ndkBuilds
Can someone tell me why my copy task is not working, i have seen some similar questions here but none of them provided a soultion...
def outputJar = "${buildDir}/intermediates/jar"
// Define some tasks which are used in the build process
task copyCompiledClasses(type: Copy, dependsOn: 'assemble') {
// get directory for current namespace
println "Copy compiled classes..."
mkdir Paths.get(outputJar,'classes')
mkdir Paths.get(outputJar,'bin')
from fileTree(dir: 'build/intermediates/javac/debug/classes/', exclude : '**/BuildConfig.class')
into outputJar+'/classes'
}
there are classes in the source folders, and my target folders are being created but the actual copying is not taking place!!!! grrrrr!
Think that the source-spec was wrongful.
task copyCompiledClasses(type: Copy, dependsOn: assemble) {
def outputDir = "${buildDir}/intermediates/jar"
mkdir "${outputDir}/classes"
mkdir "${outputDir}/bin"
from fileTree("${buildDir}/intermediates/javac/debug/classes") {
include '**/*'
exclude '**/BuildConfig.class'
}
into "${outputDir}/classes"
}
I have .cmd file that I want to include everytime build.gradle is run by Android Studio.
Let's say the filename is create-artifacts.cmd and so in my module's build.gradle.
android {
...
task createArtifacts(type:Exec) {
commandLine = ["create-artifacts.cmd"]
workingDir = file("$rootDir")
}
}
How may I be helped with this?
See the ExecTask documentation
task createArtifacts(type:Exec) {
commandLine 'cmd', '/c', 'create-artifacts.cmd'
workingDir rootDir
}
I wrote a small task, which updates an Android library from the web. This should only be done on request. I know, that there is a '-x' option, but this seems to apply only on gradle itself. The task gets executed whenever I try to build my project with Android Studio. Is there a way to exclude specific task from being executed?
My gradle task look like:
task downloadSDK {
print 'Downloading SDK...'
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
ant.get(
src: 'http://example.com/SDK.zip',
username:properties.getProperty('USERNAME', null),
password:properties.getProperty('PASSWORD', null),
dest:"${buildDir}/sdk.zip",
verbose:true)
println 'done'
}
task updateSDK(type: Copy) {
print 'Copying SDK...'
delete "src/main/java/"
def zipFile = file("${buildDir}/sdk.zip")
def outputDir = file("src/main/java")
from zipTree(zipFile)
into outputDir
println 'done'
}
updateSDK.dependsOn downloadSDK
I thought that I just have to add << to my updateSDK, but it doesn't seem to work with the Copy task.
Reading the gradle spec more deeply, I found out, that Copy is actually not a task but rather a function. So, my gradle task has to look like:
task updateSDK << {
print 'Copying SDK...'
delete "src/main/java/"
def zipFile = file("${buildDir}/sdk.zip")
def outputDir = file("src/main/java")
copy {
from zipTree(zipFile)
into outputDir
}
println 'done'
}
The difference is that I call the copy function inside a task so that doLast will work correctly.
I have a Gradle task that depends on other tasks. For instance:
//Dependent tasks will be executed first before executing requested task
makeJar.dependsOn(clearJar)
makeJar and clearJar are the task which I defined as follow:
task clearJar(type: Delete) {
delete 'build/outputs/myProject.jar'
}
task makeJar(type: Copy) {
def someString = 'build/intermediates/bundles/release/'
from(someString)
into('build/outputs/')
include('classes.jar')
rename ('classes.jar', 'myProject.jar')
}
I want to add another dependency to makeJar task. Gradle has a task called packageReleaseJar which I want to use.
Following script fails:
makeJar.dependsOn(clearJar,packageReleaseJar)
Do you know how can I use packageReleaseJar using dependsOn ?
This worked for me:
makeJar.dependsOn(clearJar, ':ModuleName:packageReleaseJar')
We can also add dependsOn when we define the task such as :
task makeJar(type: Copy, dependsOn: ':ModuleName:packageReleaseJar') {
...
}