Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errors in Android Studio unless I build/clean each time

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.

like image 834
RJB Avatar asked Feb 17 '20 18:02

RJB


People also ask

What happens when you clean a project in Android Studio?

Cleaning an Android project simply deletes the build directory. It removes the . class files that are generated when you compile your project and then recompiles again.

What is the difference between rebuild and project in Android Studio?

Difference between make and rebuild is "clean" task. When you do rebuild project it performs clean too.

What went wrong gradle could not start your build?

Your issue is some files are missing, don't delete the Gradle file and any inbuild files and classes. If you need this project try to undo what you did, or try to recover revert it back if your project is connected with the version controller.


1 Answers

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.
like image 144
Sonu Sourav Avatar answered Sep 16 '22 16:09

Sonu Sourav