I’m trying to use $BITRISE_BUILD_NUMBER in my gradle file as the versionCode, but I kept running into build error claiming that it can’t find versionCode method in gradle…
So what I did is:
versionName System.getenv(“BITRISE_BUILD_NUMBER”)
in my build.gradle file.
Anyone has an idea on why and how should I fix this? Thanks!
What went wrong:
A problem occurred evaluating project ‘:app’.
Could not find method versionCode() for arguments [143] on ProductFlavor_Decorated{name=main, dimension=null, minSdkVersion=null, targetSdkVersion=null, renderscriptTargetApi=null, renderscriptSupportModeEnabled=null, renderscriptSupportModeBlasEnabled=null, renderscriptNdkModeEnabled=null, versionCode=null, versionName=null, applicationId=fr.xebia.fashicon, testApplicationId=null, testInstrumentationRunner=null, testInstrumentationRunnerArguments={}, testHandleProfiling=null, testFunctionalTest=null, signingConfig=null, resConfig=null, mBuildConfigFields={}, mResValues={}, mProguardFiles=, mConsumerProguardFiles=, mManifestPlaceholders={}, mWearAppUnbundled=null} of type com.android.build.gradle.internal.dsl.ProductFlavor.
Am I suppose to be able to use the ENV variable directly in my gradle file? Or do I need to wrap the Bitrise ENV variables in my App variables and then pass it via command line while executing a gradle task?
Do you try to run this locally? Because BITRISE_BUILD_NUMBER is only set on bitrise.io automatically, locally you’ll have to set this manually as an environment variable, e.g. in your .bitrise.secrets.yml, or just with an export BITRISE_BUILD_NUMBER=X
Mainly, you should do a clean git clone of the repo, as there can be a file in your current directory which is not under version control, and so is not available when bitrise.io clones the repo.
Old topic, but still : If the APK versionCode is set with this buildNumber value, it must first be parsed to integer. Also, in my experience, the versionCode can not be set to 0, else the generated APK will have an empty value for versionCode (tried with aapt dump badging APK.apk).
Personally, I prefer to set an arbitrary high value when built in local. Altogether, here is what works both on Bitrise and in local for me :