Android Studio com. android. dex. DexException: Multiple dex files define (repeated reference package), androiddefine
If you use Android Studio for development and use other projects as libraries, this problem is very easy to occur. This problem occurs because the package is repeatedly referenced, which means that a package is referenced in your own project, and the same package is referenced by your project as a library, this problem occurs.
So how can we solve it? What I know is that there are two methods:
Method 1: Follow the conventions. You can see that I have added a v4 package to the library and use it as dependencies, in samples, there is also a v4 package, and it also needs to be used as dependencies. At this time, you will see repeated references when compiling:
How can this problem be solved?
You can directly modify the gradle file or change it in, as shown in:
In the gradle file, you only need to change compile to provided.
The same is true if you configure it directly. Select provided in the drop-down box. Here, you only need to change one of the projects.
Method 2:
There is a premise to use this method, that is, the package you reference is in the Library dependency, or take the v4 package as an example.
First, delete the v4 package from your libs file, delete both projects, and then re-add the reference. The method for adding the package is as follows:
In the displayed dialog box, select the v4 package:
Click OK. Note that this method must be used to introduce v4 packages for both projects.
At this time, the Scope of the v4 package introduced by you can use compile. You do not need to change one of them to provided for compilation. Of course, you can also directly write in the gradle file without the graphical operation method above.