Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Feb 24, 2017

And now please the mapping too :)

@patrickfav

This comment has been minimized.

Copy link

commented Oct 23, 2017

@dhaiwatbhavsar

This comment has been minimized.

Copy link

commented Jan 1, 2018

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

@fan123199

This comment has been minimized.

Copy link

commented Jan 23, 2018

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
You can’t perform that action at this time.