0

There are several existing questions on this, but none of the solutions seem to work for me.

I want to white label my app. The first step is to go to the project's properties and mark the project a Library Project.

Then, create a new Android Application Project, open properties, and add your Library Project to the Library section of the Android tab.

When I try to compile, I get the error:

Unable to execute dex: Multiple dex files define Lcom/facebook/android/R$drawable;

My app uses the Facebook library (not in the form of a jar). The attached screenshot shows what my workspace looks like. com_facebook_android, and another library called wheel, are not in my top project's (library project) libs folder, but they are added as libraries in properties. I think I tried to move them there once and ran into a whole bunch of problems. The app is functioning fine without them in there so I left it. I'm not sure if this is the problem or not.

Could someone point me in the right direction? Despite the existing questions on stackoverflow, I haven't been able to figure out how to make this work.

enter image description here

UPDATE:

I've almost solved the problem. I went about adding my Library Project to WhitelabelTest a different way.

I had originally gone to WhitelabelTest > Properties > Android > Library > and added my Library Project to the list. I removed this.

Instead, I went into the bin folder for my Library Project, copied the jar file (we'll call it LibraryProject.jar) and pasted it into the /libs folder of WhitelabelTest. I then right clicked LibraryProject.jar > Build Path > Add to Build Path.

This allowed me to compile the WhitelabelTest project and have it install onto my emulator.

However, when the application launched, I received the following crash:

 FATAL EXCEPTION: main
 java.lang.RuntimeException: Unable to instantiate application com.example.whitelabeltest.WhitelabelTest: java.lang.ClassNotFoundException: com.example.whitelabeltest.WhitelabelTest in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.example.whitelabeltest-1.apk]
    at android.app.LoadedApk.makeApplication(LoadedApk.java:466)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3260)
    at android.app.ActivityThread.access$2200(ActivityThread.java:117)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:969)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3683)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.ClassNotFoundException: com.example.whitelabeltest.WhitelabelTest in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.example.whitelabeltest-1.apk]
    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    at android.app.Instrumentation.newApplication(Instrumentation.java:942)
    at android.app.LoadedApk.makeApplication(LoadedApk.java:461)
    ... 11 more

Perhaps this is because my /src folder in WhitelabelTest is completely empty? I've added no new source code to WhitelabelTest. I'm purely attempting to import my Library Project into a new Android Application Project so I can share the code and just update a few drawables in /res.

Andrew
  • 20,756
  • 32
  • 99
  • 177

1 Answers1

0

It means that your total set of jars has redundant classes. Ultimately, packaging for android means compiling everything into a final product. When you just start composing off-the-shelf components it can happen that jars A and B also include classes from project C. What "several" things have you tried?

You need to look at your lib dirs and dependent projects. Possibly open up the jar files you think might be the source of the issue.

You can either get the jars from another place such that they don't conflict, get them from source and build them or edit them and remove the duplicate files. In any case you may be modifying the files which changes your distribution license.

Your best hope is that you just have the same jar included twice somehow implicitly in your project configuration.

Eric Woodruff
  • 6,380
  • 3
  • 36
  • 33
  • If I grep for `grep -ir "Lcom/facebook/android/R$drawable;" ./`, I get back 2 results: `Binary file ./facebook-android-sdk/facebook/bin/classes/com/facebook/android/R.class matches` and `Binary file ./WhitelabelTest/bin/classes/com/facebook/android/R.class matches` – Andrew Jan 24 '14 at 17:11
  • This search may be excluding jars which are zipped. You have a bin/ dir with facebook android sdk? Are you also including it as a jar or are you entirely building it from source? – Eric Woodruff Jan 24 '14 at 17:20
  • Neither the library project or WhitelabelTest's bin directories contain any obvious references to the Facebook sdk. The only possibility is the jar file in my library project's bin (we'll call it LibraryProject.jar). Since the Facebook sdk is a library for that project, perhaps it is in there. I have not included the Facebook sdk as a library for WhitelabelTest. Also, please see my update to the original post. I've included the library project into WhitelabelTest a different way and achieved a different (but not working) result. – Andrew Jan 24 '14 at 17:23
  • I take back part of my previous comment. The WhitelabelTest's bin directory contains a directory called /dexedLibs which contains, among several other jars, `com_facebook_android-ef7bddc3ee517907a8e3ff9567648e65.jar` – Andrew Jan 24 '14 at 17:29
  • I do not include a facebook sdk jar in my project. I am building from source. I've a `facebook-android-sdk` directory at the same level as my Library Project's directory and it is included in my Library Project's Properties > Android > Library – Andrew Jan 24 '14 at 17:35
  • Then does your main project have a dependency on the facebook project as well? Try making sure that there's only single inheritance in your project dependencies. – Eric Woodruff Jan 24 '14 at 17:36
  • The Facebook project is referenced in `Properties > Android > Libraries`, `Properties > Java Build Path > Libraries tab > com_facebook_android.jar is nested under Android Dependencies`, and `Properties > Project References` – Andrew Jan 24 '14 at 19:31