Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my BuildConfig class keeps getting duplicated every time I run my project

Tags:

android

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";




}
like image 901
Arron Lapta Avatar asked Nov 01 '19 23:11

Arron Lapta


People also ask

What is BuildConfig debug?

In recent versions of the Android Developer Tools (ADT) for Eclipse, there's a class called BuildConfig which is automatically generated by the build. This class is updated automatically by Android's build system (like the R class), and it contains a static final boolean called DEBUG, which is normally set to true.

How is BuildConfig generated?

BuildConfig is generated as a Java file. But having a module with mixed Java & Kotlin code impacts on build speed.


2 Answers

  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.

like image 150
CodeWithVikas Avatar answered Nov 15 '22 05:11

CodeWithVikas


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.

like image 33
Mwangi Gituathi Avatar answered Nov 15 '22 06:11

Mwangi Gituathi