8

I'm getting a list of random errors when I re-run my app in Android Studio, both with "run app" and "apply changes". I have to clean and rebuild, then it works. Error like these:

Program type already present: androidx.transition.R

Duplicate resources

error: class BuildConfig is public, should be declared in a file named BuildConfig.java

Program type already present: androidx.recyclerview.R$drawable

Program type already present: androidx.lifecycle.extensions.R$style

Type loadImageToStorage$2 is defined multiple times:

Why am I constantly getting these messages? Its slowing down my work tremendously.

It mainly seems to be about duplicate resources, but it always clears when I go do "build" and then run it.

I have uninstalled Android Studio completely, and reinstalled, and I still have the same problem. Running on mac.

Thanks so much.

auspicious99
  • 3,902
  • 1
  • 44
  • 58
RJB
  • 1,704
  • 23
  • 50
  • 2
    Create a scrap Android Studio project. Do you have the same problems with it? If yes, then there is something going on with your overall environment. If not, then the problem is tied to the specific project and the plugins, dependencies, etc. that you are using. – CommonsWare Feb 17 '20 at 18:36
  • Ive created new projects from scratch, and same problem – RJB Feb 18 '20 at 19:52
  • I have faced these issues in the past but updating to preview versions of Android Studio resolved this. Currently using the 4.0 Preview. – inventionsbyhamid May 08 '20 at 14:37
  • 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:02

3 Answers3

1

Try following ways in order of listing:

  • Select Make Project from Build menu.
  • Go to File menu and select Invalidate Cache/restart.
  • Change the distributionUrl in gradle-wrapper.properties to some other versions (higher one preferred).
    distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
  • Update Android studio.
Sonu Sourav
  • 2,926
  • 2
  • 12
  • 25
0

It seems that you have duplicate files, therefore resulting in Duplicate resources error and error: class BuildConfig is public, should be declared in a file named BuildConfig.java.

Since it is happening when you try to build, and because BuildConfig.java is generated during the build process (so, it is not a java class that you should be writing yourself), you can check if you accidentally wrote your own BuildConfig.java class, and remove it.

The BuildConfig.java class that comes from the build process, should be in the app/build/generated/source folder.

Perhaps you could check (if you are using git) that your .gitignore file is excluding generated files like BuildConfig.java.

auspicious99
  • 3,902
  • 1
  • 44
  • 58
  • I don't make accidentally another BuildConfig.java file. However, my gitignore file does not exclude BuildConfig.java. Should I add it? – RJB May 13 '20 at 18:46
  • Normally, you might not need to specify it as a single file, but the whole build folder, e.g., see https://stackoverflow.com/questions/16736856/what-should-be-in-my-gitignore-for-an-android-studio-project , see the line "build/" – auspicious99 May 14 '20 at 02:40
0

Look if you have in your build.gradle (app):

android {
buildFeatures {
    buildConfig = true
}

Try removing the buildConfig = true line.

I added it after the UI showed "cannot resolve symbol myproject.BuildConfig" to me. After that I got this compile error every time that could be helped by "clear project". Now I removed the buildConfig = true and is compiles without error while still showing the "cannot resolve"-BS.

FrankKrumnow
  • 501
  • 5
  • 13