-
-
Save pratamawijaya/78933f6e0e4af017160822438f8fed48 to your computer and use it in GitHub Desktop.
Custom gradle task which copies app-debug.apk to Desktop and renames it to Git's current checked out branch
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
// 1. Add following snippet in your build.gradle.kts(:app) | |
// Run this command in terminal -> ./gradlew copyDebugApkToDesktop | |
tasks.register("copyDebugApkToDesktop") { | |
dependsOn("assembleDebug") | |
doLast { | |
val sourceDir = "build/outputs/apk/debug/app-debug.apk" | |
val desktopDir = System.getProperty("user.home") + "/Desktop/" | |
val gitBranch = try { | |
val process = Runtime.getRuntime().exec("git rev-parse --abbrev-ref HEAD") | |
process.inputStream.bufferedReader().readText().trim() | |
} catch (e: Exception) { | |
"unknown_branch" // Default to a generic name if Git command fails | |
} | |
project.copy { | |
from(sourceDir) | |
into(desktopDir) | |
rename { "${gitBranch}.apk" } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment