Skip to content

Instantly share code, notes, and snippets.

@keyboardsurfer
Last active January 13, 2021 09:24
Show Gist options
  • Save keyboardsurfer/a6a5bcf2b62f9aa41ae2 to your computer and use it in GitHub Desktop.
Save keyboardsurfer/a6a5bcf2b62f9aa41ae2 to your computer and use it in GitHub Desktop.
Version names for application variants
android {
applicationVariants.all { variant ->
def flavor = variant.mergedFlavor
def name = flavor.getVersionName()
def versionName = name + '-' + variant.properties.get('flavorName')
if (variant.buildType.isDebuggable()) {
versionName += '-debug';
}
flavor.versionName = versionName;
}
}
@pflammertsma
Copy link

Hey Ben! It seems this doesn't work since tools version 24.4.1.

This error suggests to me that the .all method has changed:

Error:(52, 0) Could not find property 'variant' on ProductFlavor_Decorated{name=main, dimension=null, minSdkVersion=ApiVersionImpl{mApiLevel=15, mCodename='null'}, targetSdkVersion=ApiVersionImpl{mApiLevel=23, mCodename='null'}, renderscriptTargetApi=null, renderscriptSupportModeEnabled=null, renderscriptNdkModeEnabled=null, versionCode=13, versionName=1.3.2, applicationId=com.vebego.ally, testApplicationId=null, testInstrumentationRunner=null, testHandleProfiling=null, testFunctionalTest=null, signingConfig=null, resConfig=null, mBuildConfigFields={GIT_SHA=com.android.builder.internal.ClassFieldImpl@3720cfa2, LOGIN_PREFILL_PASSWORD=com.android.builder.internal.ClassFieldImpl@6c7cccce, LOGIN_PREFILL_USERNAME=com.android.builder.internal.ClassFieldImpl@a3d10b3, NAVIGATION_BAR_SHOW_CHAT=com.android.builder.internal.ClassFieldImpl@97c63a88, NAVIGATION_BAR_SHOW_PROTOCOL=com.android.builder.internal.ClassFieldImpl@d45f4cc8, NAVIGATION_BAR_SHOW_SURVEY=com.android.builder.internal.ClassFieldImpl@c34b5206}, mResValues={}, mProguardFiles=[], mConsumerProguardFiles=[], mManifestPlaceholders={}}.

Any ideas?

@pflammertsma
Copy link

Never mind, this is invalid; .all works as expected. I had an incorrect reference to an undefined variant elsewhere in my gradle script.

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