I am new to Android Studio and I am trying to get versionCode in build.gradle.
I have read this post and this post, and I tried their solution:
import com.example.BuildConfig;
...
...
...
// Get current version code
int currentVersionCode = BuildConfig.VERSION_CODE;
But IDE keeps saying Cannot resolve symbol 'BuildConfig'. Actually I haven't found any string in the whole project folder named "BuildConfig" (searched in Windows Explorer). Is there something wrong with my project configuration/creation?
defaultConfig in build.gradle (module: app) is like
defaultConfig {
applicationId "com.foo.bar"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
If you are using Jetpack Compose then you should go to your "build.gradle" file (app level), navigate to the "buildFeatures {}" block and add the following:
buildConfig = true
The block should now look like this:
buildFeatures {
compose = true
buildConfig = true
}
Hopefully it helps :)
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