I am new to Android and recently started working with Android Studio and gradle. I have a query on fetching the version number information from the gradle file.
Below is my gradle file.
defaultConfig {
versionCode 3
versionName "2.0.0"
minSdkVersion 14
targetSdkVersion 19
}
buildTypes {
debug {
buildConfigField "String", "versionNo", "\"2.1\""
}
}
Currently I am fetching the versionNo from the buildTypes as below.
String versionNo=BuildConfig.versionNo;
But I would like to fetch from the defaultConfig section. Can someone please help me on this?
Here is the answer for this question. The gradle file when built creates a BuildConfig.java file. This file contains all the information.
public final class BuildConfig {
public static final int VERSION_CODE = 3;
public static final String VERSION_NAME = "2.0.0";
public static final String versionNo = "2.1";
}
I got the version information with the below statement.
String versionNo=BuildConfig.VERSION_NAME;
Apologies for the inconvenience and Thank you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With