Monday, March 10, 2014

Handling the Android compilation error "Unable to execute dex: Multiple dex files define" in Eclipse

I have spent a lot of time trying to get an Android project using the Google Play Services and the Google Maps Android Utility libraries to compile successfully. A typical error message is shown in the screenshot below.

Eclipse was complaining about multiple dex files; eventually I found out that I was exporting out multiple jar files with the same classes and I had to toggle off the duplicate jar files in Eclipse. The following steps ensure that my project could compile successfully with the two libraries.

Add the Google Play Services and Google Maps Android Utility libraries

  1. In Eclipse, select the Android project in the Package Explorer. Right click and choose Properties.

    The Properties for xxx project appears.
  2. Choose Android. Click Add.

    The Project Selection dialog appears.

  3. Choose Google Play Services library. Click OK.

    The library is added.
  4. Repeat steps 2 and 3 to add the Google Maps Android Utility library.

    The library is added.
Check for Duplicate JARs
  1. Click Java Build Path.

    The Java Build Path page appears.
  2. Click the Libraries tab.

  3. In the JARS and class folders tree, expand the top level nodes.
  4. Make a note of any duplicate JAR files.

    Note: In this example, the android-support-v4.jar is duplicated. There is a copy in my Android project and there is another copy in the Google Maps Android Utility library.

  5. Click the Order and Export tab.

  6. Toggle off one the items that contain the duplicate JAR files e.g. the android-support-v4.jar file in my Android project.
  7. Click OK.

    The Properties for XXXX project is closed.

  8. If necessary, select Project | Clean to clean up the previous compilation temporary files and compile/run the project again.

    The project should now compile successfully.

1 comment:

Mallikarjun said...

Hi I want know how to create and use multiple dex files. Please help in that. My E-mail is

Related Posts with Thumbnails