Skip to content

Instantly share code, notes, and snippets.

@bobvanderlinden
Last active May 18, 2018 07:24
Show Gist options
  • Select an option

  • Save bobvanderlinden/897705848318b86d477faaa0cdae4a79 to your computer and use it in GitHub Desktop.

Select an option

Save bobvanderlinden/897705848318b86d477faaa0cdae4a79 to your computer and use it in GitHub Desktop.
Publish APK over S3 using Gradle
buildscript {
dependencies {
classpath "com.amazonaws:aws-java-sdk:1.3.11"
}
}
def awsCredentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey)
// 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
def amazonS3 = new AmazonS3Client(awsCredentials)
amazonS3.putObject("your-bucket", "path/where/to/store/your/apk/${dstApkFile.name}", dstApkFile)
amazonS3.putObject("your-bucket", "path/where/to/store/your/apk/${dstMappingFile.name}", dstMappingFile)
}
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