未解决的参考 BuildConfig

sav*_*ion 6 android android-studio

当我尝试重建我的项目时,出现以下错误:

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
Run Code Online (Sandbox Code Playgroud)

当我检查课程时,没有未解析的引用。

我正在使用 Gradle 版本3.3.1

我几乎尝试了诸如Invalidate Cache / Restart, Clean and Rebuild, Close and Reopen project, Reimport project, delete idea folder等的一切,但没有一个奏效。

谢谢你的帮助。

flo*_*hot 21

从 android gradle 插件8.0.0开始,您现在必须明确告诉 gradle 您要生成该BuildConfig文件。

应用程序/build.gradle


android {

    //...
    buildFeatures {
        compose = true
        buildConfig = true // <- set this to true
    }
}
Run Code Online (Sandbox Code Playgroud)


Hum*_*Bee 11

这可能是因为你还没有加入,因为该领域取得了构建,BuildConfig并在摇篮文件中声明其他变量/属性将只提供一个成功的构建。以下说明将解决此问题:

  • Build -> Clean Project
  • Build -> Rebuild Project (暂时注释任何导致编译器错误的行!)
  • Alt + Enter (Windows/Linux) or Option + Enter (macOS)BuildConfig你的密码,然后选择Import...从建议的解决方案。