in the Android Development often see this error, the reason is still worth studying.
If this is the problem that occurs on eclipse, it can basically be judged that there are identical jar packages or different jar packages in the same project, but they have the same class, so the solution is to kill each other. in Eclipse, if the jar is also reported wrong after it is deleted, it may be the result of Eclipse's cache, and restarting Eclipse will basically solve the problem.
But if something happens to On Android Studio , then it's complicated. The first thing to do is to rule out the situation in eclipse, and be careful if the problem is not resolved.
If the engineering structure is like this
Tree root
Root
├── Project1
│ └── Libs
│ └── Abc.jar
└── Project2
└── Libs
└── Abc.jar
such a structure is still very common, such as many times Libs below is Android-support-v4.jar, if the two projects only one dependent Abc.jar Then remove the problem that is not used to solve.
but the usual situation may be that both projects do need to be abc.jar, so the problem is tricky (personally , as the bug), each project needs, but a compile error.
One of my gut thoughts is to create a shared project3 that is dedicated to storing the shared jar package, so the structure becomes this way,
Tree root
Root
├── Project1//depends on Project3
│ └── Libs
├── project2//depends on Project3
│ └── Libs
└── Project3
└── Libs
└── Abc.jar
But after compiling this, it causes more "Multiple Dex files define" problem, because Project1,project2 because of dependency project3 , in the compilation phase will be Abc.jar Copy to their own project, the result is that all three projects have caused a jar package conflict with each other .
Some Google Baidu After the conclusion is that this
If you had a local jar or AAR library thatyou want to use the more than one project, you cannot just reference it directly As a local dependency. This is because the Android plugin would complain if itfinds the same jar file twice when dexing the project and all its de Pendencies. (Note that right now you can ' t actually use a local AAR file even if you onlyreference it once).
from the Android Studio 's official website explains that it's best not to use Android studio when you're using it .
But it still offers a solution.
The one-to-be-to-be-to-deploy theartifact in a repository. While it's possible, it might not be convenient dueto the overhead of managing such a repository.
This scheme means that if you put the jar in a repo, you can refer to it directly, but the management repo is troublesome, for example, we often use the compile ' com.android.support:support-v4:21.0.0 ' is getting the jar package we need from Repo(jcenter) (so if it repeats support-v4 Package, then the direct change to this has already solved the problem).
But if it's a private jar , It's too cumbersome to put it in the repo , not too realistic. or Google to the scheme, still use such a structure, but slightly modified
Tree root
Root
├── Project1//depends on Project3
│ └── Libs
├── project2//depends on Project3
│ └── Libs
└── Project3
└── Libs
└── Abc.jar
Add the following two sentences to the project3 build.gradle file
dependencies {
Compile Filetree (dir: ' Libs ', include: [' *.jar '])
}
Artifacts.add ("Default", File (' Abc.jar '))
we use the jar package as a project3 output package (for specific reasons).
PS: The reason for this is that each project relies on another project's output, the "Artifacts", where the action is to force the Abc.jar to be added as the output package for this project. It is recommended to use the beta to test the APP in a full range:http://www.ineice.com/
Android "Multiple Dex files define" error