5

I have an android app, which calls an jar lib say b.jar. This b.jar lib. is then calls facebook sdk lib. When I compile my app under this situation, it always says

Unable to execute dex: Multiple dex files define Lcom/facebook/android/AsyncFacebookRunner$1; Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/facebook/android/AsyncFacebookRunner$1;

I have used a few days to make it work, however, I failed to tackle this issue. Do anyone know how to solve this issue?

Michael Celey
  • 12,645
  • 6
  • 57
  • 62
Jacky Lam
  • 51
  • 1
  • 5
  • 1
    this is probably because the same jar is included more than once in your project. How is facebook sdk lib included, is it a jar? If so, ensure that your project only includes it once (that it doesn't appear in referenced library projects, or build paths, etc). – ab11 Mar 29 '13 at 18:36
  • I include the facebook lib project from Properties->Android->Library->Add to my b lib project. Then, I include the b lib project to my main app from Properties->Android->Library->Add. I meet this issue when I set them up in this situation. Does anyone have idea to solve it? – Jacky Lam Mar 30 '13 at 00:27
  • 1
    @JackyLam Hi, I am facing the same problem. I hope you solved the issue? Please share how did you do that? – Erma Isabel Jul 18 '13 at 09:20

3 Answers3

4

Go to the project properties and then Java build path -> Libraries -> Remove Android dependencies and OK then Run your project

Referred from : https://stackoverflow.com/a/15247670/1585773

Worked perfectly for me .

Community
  • 1
  • 1
May
  • 207
  • 2
  • 7
  • If Facebook sdks is referred as a library, then if you remove Android Dependencies from java build path then project will not compile as facebook jar appears in Android Dependencies – Jasper Jun 24 '15 at 13:44
3

All answers are a work around. They do not solve the root cause of the issue. If you look at your project structure, there is a FacebookSDK project and your Project. In both the project, you have com.facebook.android(first java file being AsyncFacebookRunner) package, which have the same java files included. Obviously multiple dex files will define your class files and you will get error.

Solution - Remove the com.facebook.android from you main project (not FacebookSDK).

Sandeep Taneja
  • 169
  • 1
  • 5
  • +1 for "all answers are a work-around". I'm scouring the internet and finding nothing but work-arounds. I'd kill for an article on how multiple project dexing works – salezica Jun 10 '15 at 18:56
0

For me this was caused by a conflict with the AddThis SDK, since the AddThis SDK includes a partial copy of the Facebook SDK embedded in it. And so the com/facebook/android/AsyncFacebookRunner class was defined twice.

I was able to resolve this using these answers:

Android AddThis sdk + Facebook sdk won't build in Android Studio

Android Studio - App Crashing on AddThis.jar - "Sources Not Found" Message

Specifically, by using this step from the second answer:

Used command zip -d addthis0.0.8.jar com/facebook/* in Terminal to delete the Facebook files from addthis0.0.8.jar

Since I'm using Eclipse, I didn't need to do any of the other steps in those answers.

Community
  • 1
  • 1
Saxon Druce
  • 17,406
  • 5
  • 50
  • 71