8

I migrated my project to Androidx and every time I run my project I keep getting this error that says class BuildConfig is public, should be declared in a file named BuildConfig.java. I know that the cause of my is that every time I build my project my java BuildConfig class keeps getting duplicated. Which gives it a name such as BuildConfig1, BuildConfig2 etc.. I constantly have to keep deleting it and rerunning my project in order to compile this is really annoying does anyone know the cause of this and perhaps a fix? This is my BuildConfig class

public final class BuildConfig {
  public static final boolean DEBUG = Boolean.parseBoolean("true");
  public static final String APPLICATION_ID = "com.examp.smartshop";
  public static final String BUILD_TYPE = "debug";
  public static final String FLAVOR = "";
  public static final int VERSION_CODE = 1;
  public static final String VERSION_NAME = "1.0";




}
Arron Lapta
  • 198
  • 2
  • 9
  • Does this answer your question? [BuildConfig is public, should be declared in a file named BuildConfig.java](https://stackoverflow.com/questions/59438157/buildconfig-is-public-should-be-declared-in-a-file-named-buildconfig-java) – starball Apr 23 '23 at 23:03

3 Answers3

4
  1. Try to clean project(Build->Clean Project) and rebuild Project(Build->Rebuild Project).

or

  1. Try deleting .gradle folder , build folders, .iml file.( You can do thing by going to Project window and choose 'project' option. And do the rebuild project again.

or

  1. last resort File->Invalidate Cashes/Restart.

Vote If it works.

Happy coding.

Thanks.

CodeWithVikas
  • 1,105
  • 9
  • 33
1

Under the project search for a folder named ".gradle" and while at it search for another under the 'app' folder named "build". Delete the two folders and run your app. It will solve the issue. See this

The error arises as a result of duplication of files hence Android Studio is unable to determine which files to use.

Mwangi Gituathi
  • 305
  • 2
  • 10
0

I had this same issue after doing some package restructuring.

I tried deleting the build and .gradle directories and restarting Android Studio with invalidating caches with no luck.

After the package restructuring, not only did my androidTest files end up in my main directory, eventually I noticed I had ended up with a BuildConfig.java in my source directory. I really should have been more careful with the refactoring preview.

Deleting the BuildConfig.java from my main/java/package directory resolved this issue for me.

CrashCodes
  • 3,237
  • 12
  • 38
  • 42