Skip to content

Instantly share code, notes, and snippets.

@mandrachek
Created November 2, 2015 21:41
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 mandrachek/0a47a0d1e48aee860d6c to your computer and use it in GitHub Desktop.
Save mandrachek/0a47a0d1e48aee860d6c to your computer and use it in GitHub Desktop.
dynamic ext.betaDistributionApkFilePath
android {
splits {
abi {
enable true
reset()
include 'x86', 'armeabi', 'armeabi-v7a', 'mips', 'arm64-v8a'
universalApk true
}
}
}
android.applicationVariants.all { variant ->
ext.betaDistributionApkFilePath = "${buildDir}/outputs/apk/app-${variant.name}-universal-${variant.buildType.name}.apk"
}
@mandrachek
Copy link
Author

This doesn't work :(

I'm trying to set the ext.betaDistributionApkFilePath dynamically so that I can account for variant name (flavor) and buildType (release/debug).

If I hardcode ext.betaDistributionApkFilePath on a per-flavor basis, I'm limited to just one buildType for that flavor. If I hardcode it for the build type, I'm limited to one build flavor for that build type.

@mikebonnell
Copy link

What error are you seeing or does the distribute just not occur?

-Mike

@dominicthomas
Copy link

dominicthomas commented Nov 25, 2016

This worked for me... put it outside of the android {} block in the main app's build.gradle:

android.applicationVariants.all { variant ->
    variant.outputs.each { output ->
        tasks.findAll {
            it.name.startsWith("crashlyticsUploadDistribution${variant.name.capitalize()}")
        }.each {
            it.doFirst {
                ext.betaDistributionApkFilePath = "${buildDir}/outputs/apk/" + variantApkName(variant, output)
            }
        }
    }
}

// Here you choose the custom file naming convention for your apk, also use when actually setting the filename.
def variantApkName(variant, output) {
    return output.outputFile.name.replace(".apk", "-v${variant.versionName}-${variant.versionCode}.apk")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment