Android Exceptions DexException

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

com.android.dex.DexException: Multiple dex files define Lcom/example/lib/Class;

This error occurs because the app, when packaging, finds two .dex files that define the same set of methods.

Usually this happens because the app has accidentally acquired 2 separate dependencies on the same library.

For instance, say you have a project, and you want to rely on two libraries: A and B, which each have their own dependencies. If library B already has a dependency on library A, this error will be thrown if library A is added to the project by itself. Compiling library B already gave the set of code from A, so when the compiler goes to bundle library A, it finds library A's methods already packaged.


To resolve, make sure that none of your dependencies could accidentally be added twice in such a manner



Got any Android Question?