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"
    }
 
     
     
     
    