Created
May 18, 2018 07:16
-
-
Save bobvanderlinden/96b1d92d6c9c1fc5a60b68d022d3208e to your computer and use it in GitHub Desktop.
Publish APK over SSH using Gradle
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
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