12

When i'm try to rebuild my project i get the error below:

warning: flag is not supported by this version of the compiler: -Xallow-no-source-files
warning: flag is not supported by this version of the compiler: -Xjava-source-roots=/Users/tyln/AndroidStudioProjects/PhoneBox/base/navigation/build/generated/source/buildConfig/dev/debug
base/navigation/src/main/java/com/raqun/phonebox/navigation/IntentLoader.kt:7:9: error: unresolved reference: BuildConfig
        BuildConfig.PACKAGE_NAME,
        ^

> Task :base:navigation:compileDevDebugKotlin FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':base:navigation:compileDevDebugKotlin'.
> Compilation error. See log for more details

When I check the class there're no unresolved references.

I'm using Gradle Version 3.3.1

I almost tried everything such as Invalidate Cache / Restart, Clean and Rebuild, Close and Reopen project, Reimport project, delete idea folder etc but none of them worked.

Thanks for your help.

savepopulation
  • 11,736
  • 4
  • 55
  • 80

6 Answers6

18

It's probably because you have not made a build since adding the field, BuildConfig and other variables/properties declared in a Gradle file will only be available AFTER a successful build. The following instructions will fix this:

  • Build -> Clean Project
  • Build -> Rebuild Project (comment any lines that cause compiler errors for now!)
  • Press Alt + Enter (Windows/Linux) or Option + Enter (macOS) on BuildConfig in your code and select Import... from suggested solutions.
HumbleBee
  • 1,212
  • 13
  • 20
8

Starting with android gradle plugin version 8, you now have to explicitly tell gradle that you want to generate the BuildConfig file.

android {

    //...
    buildFeatures {
        compose = true
        buildConfig = true // <- set this to true
    }
}
flopshot
  • 1,153
  • 1
  • 16
  • 23
2

You just need to build your app by simply clicking on Build APK(s). Fasting way to fix it.

build issue

Axes Grinds
  • 756
  • 12
  • 24
1

after I clean and rebuild the project still facing the issue.

for me it was a typo at gradle file :S, in your buildType check if there is a typo

buildTypes {

    deubg { <- it should be "debug"
        buildConfigField "String", "URL_BASE_DEBUG", '"https://example.example.com"'
        buildConfigField "String", "TOKEN_DEBUG", '"********"'
        buildConfigField "....."}


    release { 
        buildConfigField "String", "URL_BASE_PROD", '"https://example.example.com"'
        buildConfigField "String", "TOKEN_¨PROD", '"********"'
        buildConfigField "....."}
Marcos Narvaez
  • 161
  • 2
  • 6
0

Like variant. Remove special characters like : or , from root project folder name or in any path to project

PanCrucian
  • 241
  • 4
  • 6
0

I don't know why even after cleaning, and invalidating caching or deleting entire ./gradle and ./idea folder won't help to fix this issue. I was using AGP and Gradle version 8.0.2 and 8.2.1 respectively, and now I am using AGP 7.4.2 and Gradle 7.6.2 and after doing Rebuild, I see BuildConfig got resolved.

Uddhav P. Gautam
  • 7,362
  • 3
  • 47
  • 64