BuildConfig not getting created correctly (Gradle Android)
Solution 1:
Please, be sure that you are building "dev" or "prod" variant. There is no BuildConfig definition in default "debug" and "release" variant. In Android Studio, you can select current variant in bottom left corner:
To simplify your build.gradle file, you can define:
buildTypes {
debug {
buildConfigField "String", "URL_SEARCH", "\"https://dev-search.example.com\""
// etc.
}
release {
buildConfigField "String", "URL_SEARCH", "\"https://search.example.com\""
// etc.
}
}
and then just use default "debug" and "release" variants.
At last, delete semicolon (sign: ';') from the value of buildConfigField parameter.
Solution 2:
I had same issue and fixed it like below:
buildConfigField 'String', 'BASE_URL', '"https://api.example.com"'
Solution 3:
first do
File -> Invalidate Caches/Restart... -> Invalidate and Restart
then do
Build -> Clean Project
then do
Build - > Rebuild Project
Solution 4:
Just in case that helps somebody else, in my case it was a missing import:
import uk.co.yourpackage.yourapp.BuildConfig;
Somehow, nowhere in the doc does it mention you need that include! Made me think it was automatically imported somehow but it ISN'T. not for me at least... So much time lost... Hope that helps another newbie like me!