Program type already present: BuildConfig

Error: Program type already present: somemodule/BuildConfig

Cause

In my case I had a (hidden) circular dependency which Android Studio did not find:

  1. testutils/build.gradle uses implementation project(':somemodule')

  2. somemodule/build.gradle had `androidTestImplementation project(":testutils")

Solution

  • in my case the second dependency was not neccessary so I removed it

In my case It was happening when I try to run older project on new installed Android studio The problem solved by running Build->Clean Project

Note: As friends say on comments this is solution for a flutter project


I solved this error enabling multiDexEnabled in the build.gradle of my app's module:

defaultConfig { 
    ...
    ...
    ...

    multiDexEnabled true
}

You are getting this error because you a have library module which has the same package name as the app module.

The solution would be to change package name of your library module. You can follow the accepted answer in this SO which describes how to change the package name in android studio.