Last active
November 26, 2023 09:29
-
-
Save shahzadansari/31d7dc50ecd8e7c752c1841b72aa89bd 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 | |
// Note: It will replace "/" in your branch name with "-" as "/" creates a directory. | |
// fix/bug becomes fix-bug. You can adjust it as per your needs. | |
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().replace("/", "-") | |
} 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