Android Studio com.android.dex.DexException:Multiple dex files define (duplicate reference package)

Source: Internet
Author: User

If you develop with Android studio and you want to use other projects as the library, the problem is very easy to come by. This problem occurs because of a duplicate reference to the package, which means that a package is referenced in your own project, and that the same package is referenced by your project as the library.

So how to fix it, all I know is there are two ways to do it:

Method 1: in accordance with the Convention, directly, from can see I have added a V4 in the library, and I use it as a dependencies, and in samples also have a V4 package, The same also needs to be used as a dependencies, this time you go to compile will have a duplicate reference problem:

How to solve it?

You can modify the Gradle file directly, or you can change it in, as shown in:

In the Gradle file, just change the compile to provided.

If configured directly, the same is true, select provided in the drop-down box. As you can explain here, you just have to change one of the items.


Method 2:

There is a premise to use this method, that is, the package you quoted in the library dependency, or take V4 package for example.

First of all, remove the V4 package from your Libs file, delete all two items, and then add the reference again, this way, directly, by the circled Red box operation:


In the popup dialog box, select the V4 package:


Click OK. Note that the two projects here need to be changed into this way to introduce the V4 package.

At this time, you can use the scope of the two V4 package that you introduced to compile. You don't need to change one of these to provided to compile. Of course, you can also not use the above graphical operation, directly in the Gradle file is also the same write.

Android Studio com.android.dex.DexException:Multiple dex files define (duplicate reference package)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.