I am unable to build my application
I am running the latest build tools downloaded today, this started happening after the update.
-dex:
[dex] Converting compiled files and external libraries into
/Users/rob/Repos/my_app/bin/classes.dex...
[dx]
[dx] UNEXPECTED TOP-LEVEL EXCEPTION:
[dx] com.android.dx.util.DexException: Multiple dex files define
Lcom/robaldred/myapp/About$1;
I have tried cleaning and rebuilding, I've also tried in Eclipse but it gives the same error.
Anyone got any ideas? I'm at a brick wall here now.
I spent hours cleaning, creating new projects, uninstalling-reinstalling sdk... nothing worked. I didnt have any library project either ( i just had some jar files under lib). Howerver, In the end I fixed it and my steps were:
Search and clean all .apk files ( I had some in .svn folder...grr.. some developer had added some build related folders under svn)
delete bin and gen.
From eclipse project properties remove reference to library jars, press ok. Then again add them back. I had some java compiled jar library. I don't know why I had to remove and add it back, but that surely was needed.
Something happened yesterday to my system (and another here at work) where the SDK wanted to push the platform tools update but then I was unable to use it at all, etc.
I ended up moving my SDK out of the way and reinstalling it, then everything worked as it always had. I did not have your dex specific issue, but I suspect the update push yesterday broke a good many things. Good luck.
You can:
Delete folders <.settings>, <bin>, <gen>, and files <.classpath>, <.project> and <project.properties>.
Delete your project in Eclipse (right button, <Delete>) without deleting the source files.
Create a new Android project and select <Create project from existing sources> from your previous sources.
Import external libs, if needed in the build path.
It should solve this annoying problem.
Be very careful about all source files you attach to/have in your project.
I found this problem in two situations:
When I have two different android support library jars
When I accidently put in the past some Facebook src not as a library, but directly into my src directory
So all answers which says that you shouldn't put your bin/ directory into class path are also correct, but in situation where you have error like:
[2013-08-02 20:22:03 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/facebook/android/AsyncFacebookRunner$1;
[2013-08-02 20:22:03 - Activity] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/facebook/android/AsyncFacebookRunner$1;
you should look for same jars in project/libraries (this should be founded by Android Eclipse environment in most cases) or look into all sources attached to project to find multiple occurance of (as in example code above) of class com.facebook.android.AsyncFacebookRunner
I think the directory in bin change from
com/XXX/XXX
to
classes/com/XXX.
You can clean your project and solve it.
I was seeing this same problem. If you're using Android Studio, you need to make sure you don't have the 'bin' or 'gen' folders included in any of your projects when you're compiling.
After removing this I was able to compile successfully
If you're having issues because of Multiple DEX files
Remove the entire target folder and build the project again. This won't affect your project cause everything in the target folder is built again.
Change implementation fileTree(include: ['.jar'], dir: 'libs') to
provided fileTree(include: ['.jar'], dir: 'libs') in your app gradle.build> dependencies.
Make sure it has changed in your Module Settings> Dependencies {include=[*jar] dir=libs} too. It must have a scope of Provided next to it and not Implementation.
Related
if I have a project with many library projects linked, could I improve build performances by packaging each of them in an AAR and including it in the main project ? Or this will not make any difference since that when the compiler need to assemble the apk it need to package everything together anyway?
Thanks to any one who will give me some clarifcation about performance differences between the 2 approach
I don't think you will save any build time by wrapping an existing .jar file into a .aar file and using that instead of the original .jar file.
As this SO post notes, .aar files are basically just zip files which may contain a jar file and some android resources.
Also, because .aar files are not precompiled into Dalvik byte code, the build process for your apk file must still carry out that step at least once. So, you won't save dexing time just by wrapping the .jar file into a .aar file either.
If you build a typical Android Studio project (with some Android library dependencies specified in the gradle build file) you can see the directory underneath app/build/intermediates/exploded-aar where these files have been unzipped. That work must still be done by your build machine even though you are using a .aar file.
Finally, as you pointed out, the .apk packaging work must still be done at the end of the build.
I believe the Library projects (which you are using) is the best way to go because of two reasons:
The library project gives the direct access to the code base of the libraries which can be compiled and packaged together with the main app code
In case, multiple .aar files are referenced within the project, then during the apk creation the unpacking, merging of resources and Manifest file will increase the build time.
I have been noticing one major problem in android that
When I use/import couple of jars in my android app for development purpose so I get below exception:
[2011-10-23 16:23:29 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/myapp/R$array;
[2011-10-23 16:23:29 - myProj] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/myapp/R$array;
I have been noticing this problem when I import/use different jars for app development. I got to
Project->Properties->Java Build Path->Order & Export->
Then assign jars priorities.
And then I go for running project so I get this exception. And every time I struggle to solve this issue. I know this issue raise due to common contents of jar but ant to know reliable way to handle it.
That's why I want to know how to deal with this?
I faced this issue multiple dex files means your application have different source for same class.
To fix it i used use same jar file(android-support-v4.jar) for project and libraries also. (copied same jar file in project and library).
This issue arises not only with the android-support-v4.jar, it can arises with other libraries too. This generally comes when you import some library in your project.
To resolve this just figure out which jar is showing the multiple dex issue and make sure to have the same jar in your project and as well as in the libraries which you have imported. Doing this your problem will be resolved.
Check out all jar files added in lib folder of your project and all dependent library and remove jar if it is already added in another project or lib. This error will be only because of more than one source for same class.
Hi I am developing small android application using eclipse tool. I am including two jar files into my project support version-4 and another is my library jar file. When I ran my application it run successfully but i tried to use it gives me some errors regarding no class def found error. So I do to project properties and there in java build path order and export I checked two jar files. After that i clean build my project and try to run my project. SO while running my project it gives me error. Run time error is as follow:
[2013-07-08 12:19:16 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/haarman/listviewanimations/ArrayAdapter;
[2013-07-08 12:19:16 - ListViewAnimationExample] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/haarman/listviewanimations/ArrayAdapter;
I check around this problem and according solution I delete my bin and gen folder and also tried again run but it gives me same error. How to solve this problem. Is it related to my project set up or its related to eclipse? Need Help.
Thank you.
This is a build path issue. Check that your bin folder is not part of your build path. Typically you get this when you have two of the same jars, but with different versions. Are you using external libraries like ActionBarSherlock? If the android-support-v4 jar you include is a different version than the one ActionBarSherlock uses you will get this error.
Unable to execute error solution link
Also check Make sure that the value of android:targetSdkVersion in AndroidManifest.xml matches target=android- in project.properties.
I'm having this problem since I installed the new SDKs. I've read about this happening when I try to link the same class to the build twice.
But here is the peculiar thing about it:
I have an Android library project that includes a class folder on the build path.
I have this library project included in one of my regular Android projects.
I have to include the class folder in this regular project as well to make it build.
This when the error occurs.
But when I do either of the following:
Remove the class folder from the library project: The library project won't build, so the regular project won't either.
Remove the class folder from the regular project: The library project builds, but the regular project won't because it misses the class files (?!).
I seem to be stuck in some unsolvable paradigm here.
Maybe there are build rules to circumvent this?
Any help would be greatly appreciated!
Apparently the way Android library projects are linked has changed.
Before, the library's source folder would be linked to the build path.
With the new solution the library is apparently built to a jar file in its own 'bin' folder.
This is then linked as an external jar to the build path of the project using the library.
To make the conflict dissappear, do two things:
Remove the source folder link in Project properties->Java Build Path->Source
Clean the project. Perhaps clear your projects 'bin' folder manually.
Now it should work again! :)
I maintain an Android app and am not using Eclipse. I am not using Eclipse. I am using ant and build.xml and build.properties.
I have places my .jar file into the libs/ directory. My code compiles just dandy. But when I run it on the emulator, the output APK does not include the .jar, so I get a runtime stacktrace:
ERROR/AndroidRuntime(470): java.lang.NoClassDefFoundError: com.google.ads.AdView
my build.properties looks like this:
jar.libs.dir=libs
And the libs/ directory contains my .jar file.
What needs to be in build.xml so that the external .jar file is included in the APK?
Edit: In theory this answer should work, but it doesn't for me. Is it out of date? What gives? How to add external jar libraries to an android project from the command line
I just came over a similar problem and noticed that libraries should not be placed in "myprojectdir\lib". When I moved them to "myprojectdir\libs" everything started to work.
It turns out that I needed to upgrade the version of ant I was using to 1.8. During the compile process, I had been getting this error message:
Warning: Reference out.dex.jar.input.ref has not been set at runtime,
but was found duringbuild file parsing, attempting to resolve. Future
versions of Ant may support referencing ids defined in non-executed
targets.
I googled it, and found that I needed to upgrade Ant, and now I don't get this warning, and my application does not force close.
What needs to be in build.xml so that the external .jar file is included in the APK?
Just putting it in libs/ is sufficient.
my build.properties looks like this:
That line should not be necessary. It does not appear in my build.properties files that build successfully with JAR files.
If you use dexdump -f classes.dex from your project's bin/ directory, you will be able to determine whether com.google.ads.AdView made it in there. If it did not, then something is strange with your build scripts. If it did, then perhaps there is a dependent JAR that you are missing (though I would expect a VerifyError in that case).
You use 3rd party library, but you seem didn't run DX on it. Make sure that not only your code processed by DX tool (I assume Ant does it), but also all 3rd party libraries you use. You can look in 7Bee script I use to convert web applications to Android davlik format, so it can work for you too. You can find more about the script on Atjeews page.
Solution:
right click on the project in project tree and select Project
properties
select Java Build Path
select TAB Order
and Export
check GoogleAdMobAdsSdk-4.0.4.jar (or your
version SDK)
press OK
clean project by menu Project
-> Clean
rebuild project (Project – Build Automatically)