Last active
March 19, 2017 12:54
-
-
Save wuairc/5d52246b0b8aff89fd8e981375541426 to your computer and use it in GitHub Desktop.
Android: Get generated apk files on build finish.
This file contains hidden or 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
// copy to the build.gradle file of your project's application module | |
project.afterEvaluate { | |
final Set<File> possibleOutputFiles = new HashSet<>() | |
android.applicationVariants.each { | |
it.outputs.each { BaseVariantOutput output -> | |
possibleOutputFiles.add(output.outputFile) | |
} | |
} | |
final Set<File> actualOutputFiles = new HashSet<>() | |
project.tasks.matching { Task task -> | |
task.name.startsWith("package") | |
}.each { Task task -> | |
task.doLast { | |
Collection<File> outputFile = task.outputs.files.files.intersect(possibleOutputFiles) | |
actualOutputFiles.addAll(outputFile) | |
} | |
} | |
gradle.buildFinished { | |
println "Output apk count: ${actualOutputFiles.size()}" | |
actualOutputFiles.each { | |
println "\tOuput File: $it.absolutePath" | |
} | |
} | |
} |
This file contains hidden or 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
./gradlew assembleDebug | |
Output apk count: 2 | |
Ouput File: /home/ty/git/build/androidBuild/droiddemo/app/outputs/apk/app-universal-debug.apk | |
Ouput File: /home/ty/git/build/androidBuild/droiddemo/app/outputs/apk/app-armeabi-v7a-debug.apk |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment