Last active
December 8, 2021 03:10
-
-
Save tunjos/a2581b35b97f3c20a27d to your computer and use it in GitHub Desktop.
Copy release apk to custom directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} | |
} |
I have the same issue with updating Gradle version 4.1, Copy task has not been copying apk into given folder.
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
This will break with Android Gradle Plugin v3. See https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#variant_output