Gradle buildConfigField BuildConfig cannot resolve symbol
In latest android studio with gradle version 8.0.0 and above developer face this issu. When they try to import BuildConfig class with own package name but it's can't working. From the import can not found own packagename. So, developer confused why it's not showing and take to much time for solving this issue.
But this is new feature provided by latest android studio with gradle version 8.0.0 and above. So, you just place simple code as showing below in build.gradle file.
android {
buildFeatures {
buildConfig = true
}
}
Why use buildFeatures?
A list of build features that can be disabled or enabled in an Android Application project. A list of build features that can be disabled or enabled in an Android Dynamic Feature project.
buildConfig
abstract var buildConfig: Boolean?
Flag to enable/disable generation of the BuildConfig class.
Setting the value to null resets to the default value. Default value is true.
You can override the default for this for all projects in your build by adding the line android.defaults.buildfeatures.buildconfig=true in the gradle.properties file at the root project of your build.
Remove the = (equals symbol), as that is what the error is complaining about
buildFeatures {
buildConfig true
}
for a example of complex app/build.gradle, check out https://github.com/TeamNewPipe/NewPipe/blob/master/app/build.gradle
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