Skip to content

Instantly share code, notes, and snippets.

@tunjos
Last active December 8, 2021 03:10
Show Gist options
  • Select an option

  • Save tunjos/a2581b35b97f3c20a27d to your computer and use it in GitHub Desktop.

Select an option

Save tunjos/a2581b35b97f3c20a27d to your computer and use it in GitHub Desktop.
Copy release apk to custom directory
def publish = project.tasks.create("copyReleaseApkToCustomDir")
publish.description "Copies release apk to custom directory"
android.applicationVariants.all { variant ->
if (variant.buildType.name.equals("release")) {
variant.outputs.each { output ->
if ( output.outputFile != null && output.outputFile.name.endsWith('.apk')) {
def task = project.tasks.create("copyAndRename${variant.name}Apk", Copy)
def outputFile = output.outputFile
println "Creating " + rootProject.name + "-${versionName}.apk" + " from " + project.name + "-${variant.name}.apk"
def fileName = outputFile.name.replace(project.name + "-${variant.name}.apk", rootProject.name +"-${versionName}.apk")
output.outputFile = new File(outputFile.parent, fileName)
println "Copying "+ rootProject.name + "-${versionName}.apk" + " to apk directory..."
task.from(output.outputFile)
task.into(buildDir.parent + "/../apk")
println "Done"
task.dependsOn variant.assemble
publish.dependsOn task
}
}
}
}
@PaulWoitaschek
Copy link
Copy Markdown

And now please the mapping too :)

@patrickfav
Copy link
Copy Markdown

@dhaiwatbhavsar
Copy link
Copy Markdown

I have the same issue with updating Gradle version 4.1, Copy task has not been copying apk into given folder.

@fan123199
Copy link
Copy Markdown

Need to upgrade to support android gradle plugin v3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment