I was wondering is there a way of avoid multiple dex error ? I am using a library, I need some of its old classes from an older version and some of its new from a newer version. So when I add both jars then I get a multiple dex error. I know the cause of error, that is the both jars has same package name and same classes name.
Is there a way of avoiding this error? Is not could you please suggest an alternative. That'll be really helpful. But I've to use both jars.
Right click your project->properties->Java build path ->order and export.Then Uncheck android.support jar.
Then clean your project and run
Related
I'm using many applications in one project like :
So i have some questions here, Application must implement iterated libraries ?
Assume i have com.android.support:appcompat in my "app" gradle and have the same one in my "opencv-java" gradle the apk will compiled with both libraries and double the size?
If no, then what happened in compiling process?
If yes, How i can avoid this, is there a way or some thing?
Update :
If i have libraries (e.g: "volley", "support" etc..) in my app "gradle" and also i used it in my open-cv "gradle", that's make me able to remove those libraries from app "gradle", it's seems that main app that used compile project(':another-app') in "gradle" can use another-app libraries, with codes and assets, every thing.
the apk will compiled with both libraries and double the size?
No.
then what happened in compiling process?
Well, one of two things:
If you use compile "com.android.support:appcompat-v7" consistently, Gradle will only use one copy of that dependency.
Your build could fail with an error message complaining about duplicate Java classes, stemming from the duplicate libraries. This would happen if you are not actually using com.android.support:appcompat-v7 in one place, but instead are adding appcompat-v7 by some other means (e.g., directly compiling against a copy of that library project).
What can't happen is your double-the-size scenario, as you cannot have two copies of the same Java class in a single APK.
Is it possible to use Multidex inside a library project? It's not so hard to hit the 65k limit when you have libraries like Dagger, RxJava and Databinding. I'm really stuck here, any help would be really appreciated.
I am trying to 100% validate that this is true but based on how the normal build process works my hypothesis is that because your AAR consists of .class files and the normal android build process includes dexing all project files including libraries (AARs, and JARs) that adding multidex to your library really will just help with making sure that when they library is built in its root project that it is able to multi-dex properly.
Let's say you you build an AAR (which needs Multi-Dex) and then you import that aar into another project. Chances are you are going to need multi-dex on the project consuming the library as well because though the compiler doesn't need to compile the java classes it will still need to dex and do resource compilation on the entirety of the AAR.
I am implementing C2Call library for dial call purpose in one application, and C2Call library has lots of jar files, simple-xml-2.6.7.jar is part of C2Call library.
simple-xml-2.6.7.jar is giving me an error in my application at compile time:
[2014-08-21 11:09:56 - Dex Loader] Unable to execute dex: Multiple dex files define Lorg/simpleframework/xml/Attribute;
[2014-08-21 11:09:56 ] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lorg/simpleframework/xml/Attribute;
I've done a lot of surfing to solve this problem, but I can not find solution to resolve this problem.
I hope, you can give solution for this problem.
Thanks.
This problem happens if you are importing the same library in two different jars. You need to carefully check all the jars and try to find out the jars which are importing the same libraries. If you have the source code then you can easily build the jar again without adding the library.
Another thing to try is to break it into multiple dex files. Please read from here
http://android-developers.blogspot.co.il/2011/07/custom-class-loading-in-dalvik.html
"Big apps can contain more than 64K method references, which is the maximum number of supported in a dex file. To get around this limitation, developers can partition part of the program into multiple secondary dex files, and load them at runtime."
I think you have more than 64k method references and that is causing the problem. Let me know if it works for you
It happens when you try to export same jar file twice in single .apk file.
Simple way to eliminate this error
Check your:-
Android private libraries
Referenced Libraries
Android Dependencies
and make sure that no jar file is repeated.If any jar file is repeated then find it in libs folder of your project and delete it and then refresh the project.
If this does not solve then try:-
Right Click Project>Properties>Java Build path>Order and Export> uncheck android private Libraries.
I added MobFox simple-xml-2.7.1.jar file to Android lib file. When i generated apk i have this error. Delete simple-xml-2.7.1.jar after regenerate apk. I solved my problem by this way.
I'm using the commonsguy cwac-camera library, as per the demo-layout example, documented in "Working directlly with cameraview".
All is fine referencing camera/ and camera-v9/ as Android library projects in source form (I need Android 2.3 compatibility, that's what camera-v9 is for).
When I switch to using the library via JARs:
- cwac-camera-v9-0.6.8.jar only includes CameraFragment and BuildConfig classes, so I need also cwac-camera-0.6.8.jar with the other classes.
- including both JARs causes the following self-explaining error when running the project (not at compile time) Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/commonsware/cwac/camera/BuildConfig;
I could just use the source as library project, or use Gradle, but I want to know if this is a bug to open an issue on Github, or if I'm doing something wrong.
To replicate the error, just clone the demo-layout example add both .jar files to libs folder, and run the project.
No, this appears to be my fault. They must have changed something in the Gradle build process that I am using to create the JARs. I will try to fix this tomorrow. In the meantime, you could go into the cwac-camera-v9 JAR and try removing the classes in com.commonsware.cwac.camera, leaving only those classes incom.commonsware.cwac.camera.acl.
My apologies for this, and thanks for pointing it out!
My Android project contains a plenty of Java libraries that are compiled to dex each time I launch my application. The libraries do not change. Is there any way to precompile those libraries to dex? It make useless work each time compiling the same libraries to dex while making apk.
I had similiar problem and have found a solution, you have to use (undocumented) --incremental switch with dex too. Refer to this solution on SO for more information.
This might be the only current workaround: http://android-developers.blogspot.com/2011/07/custom-class-loading-in-dalvik.html