'Gradle issue with extracting tar.gz files

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


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source