Skip to content

Instantly share code, notes, and snippets.

@bobvanderlinden
Created May 18, 2018 07:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobvanderlinden/96b1d92d6c9c1fc5a60b68d022d3208e to your computer and use it in GitHub Desktop.
Save bobvanderlinden/96b1d92d6c9c1fc5a60b68d022d3208e to your computer and use it in GitHub Desktop.
Publish APK over SSH using Gradle
ant.taskdef(
name: 'scp',
classname: 'org.apache.tools.ant.taskdefs.optional.ssh.Scp',
classpath: configurations.sshAntTask.asPath
)
// Publish APK and mapping file over SCP
android.applicationVariants.all { variant ->
if (variant.buildType.name != "release") {
return
}
def buildTypeName = variant.buildType.name
def flavorName = variant.productFlavors[0].name
def publishWebApkTask = task("publishWeb${flavorName.capitalize()}").doLast {
def publishDir = file("${buildDir}/publish")
def versionName = variant.versionName
def srcApkFile = variant.outputs.find { variantOutput -> variantOutput instanceof com.android.build.gradle.api.ApkVariantOutput }.outputFile
def baseName = "drivedroid-${flavorName}-${versionName}"
def dstApkFile = file("${publishDir}/${baseName}.apk")
def srcMappingFile = file("${buildDir}/outputs/mapping/${flavorName}/${buildTypeName}/mapping.txt")
def dstMappingFile = file("${publishDir}/${baseName}-mapping.txt")
publishDir.mkdirs()
dstApkFile.bytes = srcApkFile.bytes
dstMappingFile.bytes = srcMappingFile.bytes
ant.scp(
file: "${dstApkFile}",
todir: 'yourusername@yourhost:/path/where/you/want/to/store/the/apk/',
keyfile: "${yourKeyFile}",
passphrase: '',
trust: true
)
ant.scp(
file: "${dstMappingFile}",
todir: 'yourusername@yourhost:/path/where/you/want/to/store/the/apk/',
keyfile: "${yourKeyFile}",
passphrase: '',
trust: true
)
}
publishWebApkTask.group = "publish"
publishWebApkTask.dependsOn variant.outputs.first().assemble
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment