title: Android Studio. Can't include external library properly
body: <p>I'm trying to add to classpath external library <a href="http://xstream.codehaus.org/" rel="noreferrer">(this one)</a>. The way I do it: <code>File -&gt; Project Structure -&gt; Dependencies tab -&gt; Add file dependency</code>. Is that correct? Maven's list of libraries doesn't have Xstream. And if I click <code>add module dependency</code> the list is empty. </p>
  
  <p>All I need is to add 3 jar files to classpath - <code>xstream1.4.7.jar</code>, <code>xmlpull-1.1.3.1.jar</code> and <code>xpp3_min-1.1.4c</code>. So I did it as wrote before. The thing is that after this I can include this library and everything seems Ok. But after running the project there is an error:</p>
  
  <pre><code>    Error:Execution failed for task ':gridview:dexDebug'.
  &gt; com.android.ide.common.internal.LoggedErrorException: Failed to run command:
      D:\adt-bundle-windows-x86_64-20140321\sdk\build-tools\android-4.4.2\dx.bat --dex --output D:\Mobile devices\Course Work\android studio\gridview\gridview\build\dex\debug D:\Mobile devices\Course Work\android studio\gridview\gridview\build\classes\debug D:\Mobile devices\Course Work\android studio\gridview\gridview\build\dependency-cache\debug D:\Mobile devices\Course Work\android studio\gridview\gridview\build\pre-dexed\debug\classes-80f8711ee653afcf7efe6b620bb026841cb6946a.jar D:\Mobile devices\Course Work\android studio\gridview\gridview\build\pre-dexed\debug\support-v4-19.1.0-269b660d78e582ad08c396ce1a171205a775b0a0.jar D:\Mobile devices\Course Work\android studio\gridview\gridview\build\pre-dexed\debug\xmlpull-1.1.3.1-e45616f42a2838037b23e662d2381fe8ba29f039.jar D:\Mobile devices\Course Work\android studio\gridview\gridview\build\pre-dexed\debug\xpp3_min-1.1.4c-26abc774a3b821df830ea21d4b6b0daf1ce5acb6.jar D:\Mobile devices\Course Work\android studio\gridview\gridview\build\pre-dexed\debug\xstream-1.4.7-12d1ec007d50d7a5412e6ce3abef54fbab1046d4.jar D:\Mobile devices\Course Work\android studio\gridview\gridview\build\pre-dexed\debug\xstream-benchmark-1.4.7-574037033c1552eddf3ff5624f95bc8d3d954d28.jar
  Error Code:
      2
  Output:
      UNEXPECTED TOP-LEVEL EXCEPTION:
      com.android.dex.DexException: Multiple dex files define Lorg/xmlpull/v1/XmlPullParser;
          at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
          at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
          at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
          at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
          at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
          at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
          at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
          at com.android.dx.command.dexer.Main.run(Main.java:230)
          at com.android.dx.command.dexer.Main.main(Main.java:199)
          at com.android.dx.command.Main.main(Main.java:103)
  </code></pre>
  
  <p>Moreover, I have tested this library in Intelij with common java, not android. And that worked perfectly. So I just copied working code into Android Studio from Intelij and that error occurs. </p>
  
  <p>Here's the code where this error occurs (if needed):</p>
  
  <pre><code>FileReader reader = new FileReader("boards.xml");  // load file
  XStream xstream = new XStream();
  xstream.processAnnotations(Boards.class);
  xstream.processAnnotations(IdBoards.class);
  Boards boards = (Boards) xstream.fromXML(reader); // parse xml into array list
  </code></pre>
  
  <p>So the question is <strong>How to add external libraries properly to Android Studio?</strong> Or probaby there's some other problem? Thanks for advices.</p>