首页 > 解决方案 > 未解决的参考 BuildConfig

问题描述

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

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

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

我正在使用 Gradle 版本3.3.1

我几乎尝试了诸如此类的所有东西,Invalidate Cache / Restart, Clean and Rebuild, Close and Reopen project, Reimport project, delete idea folder但没有一个起作用。

谢谢你的帮助。

标签: androidandroid-studio

解决方案


这可能是因为您在添加字段后尚未进行构建,并且在 Gradle 文件中声明的其他变量/属性只有在成功构建之后BuildConfig才可用。以下说明将解决此问题:

  • Build -> Clean Project
  • Build -> Rebuild Project(现在评论任何导致编译器错误的行!)
  • Alt + Enter (Windows/Linux) or Option + Enter (macOS)BuildConfig您的代码中按下并Import...从建议的解决方案中进行选择。

推荐阅读