3

I want to process generated .apk after gradle build. However, the place where the generated file resides depends on product flavor and build type. So how can I get those in the task?

Here's the relevant section of build.gradle:

productFlavors {
    normal { }
    tinybuild {}
}
// The following two blocks copy the generated .apk to server so that tablet you're working on can download it fast
task copyDebugAPK(type: Exec) {
    workingDir "$projectDir/.."
    commandLine 'python', 'myscript.py', 'script parameter'
}
afterEvaluate {
    packageNormalDebug.finalizedBy(copyDebugAPK)
    packageTinybuildDebug.finalizedBy(copyDebugAPK)
}

I could simply declare multiple tasks, one for each flavor / build, but I'm pretty sure that even using the script in flavor / build-type-dependent context should provide me with the relevant fields right within the task. Am I wrong?

Edit: after Robert's suggestion, I modified my task like so:

task copyDebugAPK(type: Exec) {
    android.applicationVariants.all { variant ->
        print("${com.android.build.OutputFile.ABI}")
        print("${variant.name}")
        print("${variant.flavorName}")
        print("${variant.versionName}")

        workingDir "$projectDir/.."
        commandLine 'python', 'myscript.py', '${variant.name}'
    }
}

However, no prints are being printed. I also added the variables to script input, but they are not resolved.

velis
  • 8,747
  • 4
  • 44
  • 64

0 Answers0