NoClassDefFoundError - Eclipse and Android - java

I'm having a problem trying to run an Android app which, up until adding a second external library to its build path, was working fine. Since having added the scoreninja jar, I now get a NoClassDefFoundError when I try to run the app.
Here's the message:
02-11 21:45:26.154: ERROR/AndroidRuntime(3654): java.lang.NoClassDefFoundError: com.scoreninja.adapter.ScoreNinjaAdapter
As all of the build scripts are generated by the Android tools (?), I'm not sure what else I can do other than cleaning and rebuilding or restarting eclipse (I have already tried all three). Does anyone know how I can amend this?

I had this problem after updating ADT.
I was storing all of my JAR files in a folder called "lib" and adding the jars to the build path the normal Eclipse way. This worked fine until my update.
After my update, I was getting the NoClassDefFoundError for a class that I could clearly see was included in the jar (checking out the ReferencedLibraries classes).
The solution was to remove my jars from the build path and rename my "lib" folder to "libs". This is an ant convention, and seems to be the way the new ADT finds and includes libraries in an .apk file. Once I did this, everything worked fine.

I didn't have to put the jar-library in assets or lib(s), but only tick the box for this jar in Properties -> Java Build Path -> "Order and Export" (it was listed before, but not selected)

By adding the external jar into your build path just adds the jar to your package, but it will not be available during runtime.
In order for the jar to be available at runtime, you need to:
Put the jar under your assets folder
Include this copy of the jar in your build path
Go to the export tab on the same popup window
Check the box against the newly added jar

I had this for MapActivity. Builds in Eclipse gets NoClassDefFound in debugger.
Forgot to add library to manifest, inside <Application>...</Application> element
<uses-library android:name="com.google.android.maps" />

I have changed the order of included projects (Eclipse / Configure Build Path / Order and Export). I have moved my two dependent projects to the top of the "Order and Export" list. It solved the problem "NoClassDefFoundError".
It is strange for me. I didn't heard about the importance of the order of included libraries and projects. Android + Eclipse is fun :)

I'm not sure if this is related, or if you're even still looking for an answer, but I came across this thread while trying to research the same error (but possibly for different reasons).
I couldn't find any solutions online, but an answer on a similar thread got me thinking and realized I probably just needed to rebuild (or clean) the project.
In Eclipse, go to Project => Clean. Select your project and Eclipse seemed to fix it itself. For me this solved the problem.
Hope this helps.

I have encountered the same issue. The reason was that the library that I was trying to use had been compiled with a standard JDK 7.
I recompiled it with the -source 1.6 -target 1.6 options and it worked fine.

Same thing worked for me: Properties -> Java Build Path -> "Order and Export"
Interestingly - why this is not done automatically?
I guess some setting is missing. Also this happened for me after SDK upgrade.

Right click your project folder, look for Properties in Java build path and select the jar files that you see. It has worked for me.

John O'Connor is right with the issue. The problem stays with installing ADT 17 and above. Found this link for fixing the error:
http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17

I tried everything from this post (and some other posts), and it didn't worked for me, this is by far the most terrible ADT upgrade I have experienced, and I will never upgrade without a working ADT backup.
I managed to solve it by removing the project, and then adding it again using a source backup I had.

I had this same error with ADT22. Resolved it checking "Android Private Libraries" in properties -> Java build path -> Order and export. If you are using any library projects, the same should be done for them as well.

All the existing answers don't work for me because my case is a little bit different. It took me a few hours to get it to work. I'm using Eclipse.
My android project includes another normal java 1.6 project, which needs a 3rd party jar file. The trick is:
include the jar in the normal java project for it to compile (only), don't check it in the "Order and Export" tab
also copy this jar file into the "libs" folder of the android project so it'll be available in runtime
Hope this help those who have similar scenarios like mine.

sometimes you have to take the whole external project as library and not only the jar:
my problem solved by adding the whole project (in my case google-play-services_lib) as library and not only the jar. the steps to to it (from #style answer):
File->New->Other
Select Android Project
Select "Create Project from existing source"
Click "Browse..." button and navigate to
the wanted project
Finish (Now action bar project in your workspace)
Right-click on your project -> Properties
In Android->Library section click Add
select recently added project -> Ok

Sometimes it will happen due to not including jar, which you have dependency, with "uses-libary" tag in your AndroidManifest.xml.
Also, make sure it should be inside "application" tag.
Regards,
Ravi

I had this problem and it was caused by not "exporting" the library.Issue was just because the .class files for some classes are not available while packaging the APK.Compile time it will work fine with out exporiting
In my case I was using "CusrsorAdapter" class and under "JavaBuildPath->Order and Export" I didn't check the support V4 jar.Once it is selected issue is gone.
To make sure you are getting noClassDefFound error because of above reason, please check your logacat, you will see unknown super classs error at run time.

Acutally you have reached the infamous 64k limit issue, you need to enable multidex.
This is how you do it.
https://developer.android.com/tools/building/multidex.html

I tried various things and the reason for error in my case was conflict between maps.jar and Google Api in Java Build Path-> Libraries. So, when i removed the maps.jar it worked fine.
Regards,
wahib

please make sure your jar file is in the libs directory of your project in you are using newer ADT version with your eclipse.

I got the exact same problem ... To fix it, I just removed my Android Private Libs in "build path" and clicked ok ... and when i opened op the "build path" again eclipse had added them by itself again, and then it worked for me ;)...

i spent two days trying to solve this issue after updating ADT. finally i was lucky to get this post here:
https://code.google.com/p/android/issues/detail?id=55304
which led me in the right direction. when you follow the solution - remember to replace the android support library of all your projects to the same version (remove it and re-install it to the projects). i hope this helps - good luck

If you prefer to know which files the workaround is related to here's what I found. Simple change the .classpath file to
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
Replace the .classpath file in all library projects and in main android project. The .classpath file is in the root folder of the eclipse project. Of cause don't forget to add your own classpath entries, should you have any (so compare with your current version of .classpath).
I believe this is the same result as going through the eclipse menus as componavt-user explained above (Eclipse / Configure Build Path / Order and Export).

The solution here worked for me. It's a matter of importing the library to the libs folder, then modifying the build.gradle file and then cleaning with gradlew.

If you change your order and export in your project build path, this error will not occur.
The other way of achieving it is through .classpath in your project folder.

Try this:-
Step 1
Add all the libraries to build pat in Eclipse( means make all libraries referenced libraries)
Step 2
Delete R.java file and again build the project. Don't worry, R.java will automatically get recreated.
Chill :)

As i understood, your Project shows no errors, because you included the Jar. But the Jar won't be used, when your Project got "exported" to the device.
Try this
Project -> Properties
Java Build Path / Order and Export
[✔] Your Jar

This happens quite very often to me.
Last time that happened I can remembered was caused by switching the Eclipse ADT (Google special edition) to Android Studio, and switching back. I basically tried all methods that I can found on stackoverflow which didn't work for me.
Eventually, I got the app working again (no more NoCalssDeffoundError) by switching my IDE to original Eclipse (Kepler) with ADT.

Related

Cannot resolve symbol - IntelliJ [duplicate]

This problem happens intermittently for different libraries and different projects.
When trying to import a library, the package will be recognized, but the class name can't be resolved.
If on the import statement, I right-click -> Goto -> the package's declaration, I see all the decompiled classes displayed in the side pane -- Including the ones I need --
If I try to auto-complete the import statement, I notice the class I need is not featured in the dropdown.
I tried invalidating caches already, doesn't work. I cannot find any class conflicts -- there is no other jar file in my classpath with the same package name.
I am able to import this class into other projects.
Please see screen shots:
Anyone have a clue?
You can try invalidating the cache and restarting IntelliJ, in many cases it will help.
File -> Invalidate Caches/Restart
There can be multiple reasons for this. In my case it was wrong source root issue. Invalidate caches didn't work along with other solutions.
Check your module source roots.
Project Structure (Ctrl+Alt+Shift+S).
Modules
Select your problem module.
Change tab on top of window "Sources".
Remove unwanted source roots. Keep one and add src and test source roots in this root.
File -> Invalidate Caches/Restart
And
Build your project
IntelliJ has issues in resolving the dependencies.
Try the following:
Right click on pom.xml -> Maven -> Reimport
Again Right click on pom.xml -> Maven -> Generate sources and update folders
Run this command in your project console:
mvn idea:idea
Done.
Had this issue many times. Tried 'Invalidate Cache & Restart' and all other solutions. Running that command works perfect to me.
I'm currently using IntelliJ 2019.2, but this also happened in previous versions and solution worked as well.
File -> Invalidate Caches/Restart or rebuilding the project did not work wor me.
What worked for my Gradle project was to "Refresh all Gradle projects" from the Gradle tab on top-right corner of IntelliJ v2017, using the yellow marked button shown below:
Check your module dependencies.
Project Structure (Ctrl+Alt+Shift+S).
Modules
Select your problem module.
Change tab on top of window "Dependencies".
Check what needed library (maybe, you need to add specified library
in the tab 'libraries') or module has listed here and it has right
scope ('complile' mostly).
I faced a similar issue, Mike's comment helped me move in the direction to solve it.
Though the required library was a part of the module in my project too, it needed a change of scope. In the module dependency, I changed the scope to "Compile" rather than "Test" and it works fine for me now.
Had the same problem till I noticed that the src folder was marked as root source instead of java!
Changing to only the java (src/main/java) to be the source root solved my problem
I found the following answer from #jossef-harush and #matt-leidholm useful from another link
in IntelliJ editor, click on the red keyword (Integer for example) and press ALT + ENTER (or click the light bulb icon)
select Setup JDK from the intentions menu
click on Configure
In my case, the JDK path was incorrect (pointed on /opt/jdk1.7.0_51 instead of /opt/jdk1.7.0_65)
click on the ... and browse to the right JDK path
let's clear the cache
Right click on pom.xml file, go to Maven click on Reimport. I had similar problem and this worked for me.
After a long search, I discovered that a dependency was somehow corrupted on my machine in a maven project. The strange thing was that the dependency was still working correctly in the compiled java code. When I cleaned and rebuilt my maven dependency cache however, the problem went away and IntelliJ recognized the package. You can do this by running:
mvn dependency:purge-local-repository
Intrestingly, the source of my problem hence wasn't IntelliJ, but maven itself.
For 2020.1.4 Ultimate edition, I had to do the following
View -> Maven -> Generate Sources and Update Folders For all Projects
The issue for me was the libraries were not getting populated with
mvn -U clean install from the terminal.
Try cleaning maven from upstream by:
mvn -U clean install
I also got this error for multiple times when I try to build a new java project.
Below is the step how I got this stupid issue.
Create an empty project, and create new directory src/main/java.
Create the source package net.gongmingqm10.sketch.
Use gradle wrapper, gradle idea to build the gradle stuff for the project.
Add some dependencies in build.gradle file, and gradle build, reimport the project.
Create User.java and School.java in the existing package net.gongmingqm10.sketch
I got the error while I try to use import School in User.java.
Intellij keeps complain can not resolve symbol on import.
Solution:
Build the project first, and mark the main/java as the source root. Create a new directory with the same name net.gongmingqm10.sketch. Move all the files from the old troubling packages to new package.
Root cause:
Directory tree of source code
As you can see from the tree. I got a directory named net.gongmingqm10.sketch. But what we really need is the 3 levels directory: net->gongmingqm10->sketch
But before I finish building my project in Intellij, I create new directory named net.gongmingqm19.sketch, which will give me a real directory with the name net.gongmingqm10.sketch.
When we trying to import it. Obviously, how can intellij import the file under the weired directory with the name a.b.c.
#Anton Dozortsev I was driven crazy by a similar behavior; I ended up re-installing the IDE a bunch of times, only getting past the issue after removing the IDEA app, all caches, preferences, etc.
I tried all kinds of steps in the interim, (like restarts, invalidations, deleting .idea and *.iml files, and others.)
Turns out, the problem was due to IntelliJ's idea.max.intellisense.filesize setting. I had set it to 100KB, which was smaller than my dependency's size, leading to IntelliJ showing it as unknown, just like in your screenshot.
Fix:
Click on Help -> Edit Custom Properties
Set the property to a larger value; the default is 2500KB
idea.max.intellisense.filesize=2500
Please try File-> Synchronize. Then close and reopen IntelliJ before you invalidate.
Once I restarted. I would have invalidated but the synchronize cleared everything after restarting.
Simple Restart worked for me.
I would suggest first try with restart and then you may opt for invalidating the cache.
PS : Cleaning out the system caches will result in clearing the local history.
I found the source cause!
In my case, I add a jar file include some java source file, but I think the java source is bad, in Intellij Idea dependency library it add the source automatic, so in Editor the import is BAD, JUST remove the source code in "Project Structure" -> "Library", it works for me.
What did it for me is to edit the package file in the .idea folder as I accidentally added sources to this jar library and android couldn't resolve it by deleting the sources line as marked in the b/m picture library error.
Then rebuild the gradle and bam problem solved.
I had the same issue and the reason for that was incorrect marking of the project's sources.
I manually created the Root Content and didn't notice that src/main/test folder was marked as Sources instead of Tests. So that is why my test classes were assumed to have all their test libraries (JUnit, Mockito, etc.) with the scope of Compile, not Test.
As soon as I marked src/main/test as Tests and rebuilt the module all errors were gone.
I had this recently while trying to use Intellij to work on NiFi, turned out the issue was that NiFi requires Maven >= 3.1.0 and the version that I'd checked out with (I guess my default) was 3.0.5. Updating the Maven version for the project fixed it, so in some cases Maven version mis-alignment can be a thing to look...I'd guess it's fairly unusual but if you get this far on the thread you're probably having an unusual issue :)
file-> Project Structure -> Modules, find the module with problems, click it and choose the Dependencies tab in the right side. Click the green plus sign, try to add the jar or libraries that cause the problem. That works for me.
Nothing I tried above worked for me (not that I tried every suggestion). What finally did the trick was to rename the class -- I just added a 2 to the class name and filename. Then I resolved all the references manually. (Since they weren't recognized, the refactoring did not change the references automatically.)
Once the "2-version" was happily resolved everywhere, I was then able to refactor and remove the 2 from the class and file, and everything was then as it should be.
in my case the solution was to add the project as maven project, besides the fact that i imported as maven project :P
go to pom.xml -> right click -> add as maven project
My issue was my Maven plugin got disabled after an update. I went to Help -> Find Action... -> Typed in Maven and found that it was "Off". I clicked the toggle switch and after a bit of loading it was re-enabled.
Also, check your class is not in compile exclusions
If you see, that there is a little grey cross in left top corner, you must remove class from compile exclusions
How to remove
Old question, '21 response. I ran into the issue where my go build would build code successfully but my Goland IDE showed missing modules or dependencies. I tried Invalidating Caches and Restart, but had the same problem. From another S/O thread, I tried adding the GO111MODULE=on to my Path Variables, but that didn't resolve the IDE problems either.
What worked for me was picking the correct GOROOT path in Preferences > Go > GOROOT.
I had two versions of go installed, one by brew and one from the online Go installer. I selected the brew install path, and my IDE was able to resolve the dependencies properly.
I've tried all the complicated methods and they didn't work, since I was too lazy to re-import the project I tried something else.
Mine is a gradle project, so I went to my gradle.build file, removed the dependency, refreshed the dependencies, then added the dependency again and refreshed again, the imports started working after that.
Faced similar issue,
I Updated Intellij and error start coming - Can't Resolve Symbols.
Went to Plugins, Updated the plugins & Restart
Problem Solved !!

Libgdx Conversion to dalvik format failed with error 1 [duplicate]

In my Android application in Eclipse, I get the following error.
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lorg/xmlpull/v1/XmlPullParser;
....
Conversion to Dalvik format failed with error 1
This error only appears when I add a specific external JAR file to my project. I searched for a long time for a possible solution, but none of them work.
I even tried to change to Android 1.6 instead of 1.5 (the current version I use).
Go to Project » Properties » Java Build Path » Libraries and remove all except the "Android X.Y" (in my case Android 1.5). click OK. Go to Project » Clean » Clean projects selected below » select your project and click OK. That should work.
It is also possible that you have a JAR file located somewhere in your project folders (I had copied the Admob JAR file into my src folder) and THEN added it as a Java Path Library. It does not show up under the Package Explorer, so you don't notice it, but it does get counted twice, causing the dreaded Dalvik error 1.
Another possible reason could be package name conflicts. Suppose you have a package com.abc.xyz and a class named A.java inside this package, and another library project (which is added to the dependency of this project) which contains the same com.abc.xyz.A.java, then you will be getting the exact same error. This means, you have multiple references to the same file A.java and can't properly build it.
In other ways this may be occurred if you accidentally or knowingly edit/ add any thing in the class path file manually .In certain cases we may add android.jar path manually to classpath file for generating java doc.On removing the that after javadoc generated code will works fine.Please check this too if any one still occurs.
I solved the problem.
This is a JAR file conflict.
It seems that I have two JAR files on my buildpath that include the same package and classes.
smack.jar and android_maps_lib-1.0.2
Deleting this package from one of the JAR files solved the problem.
Windows 7 Solution:
Confirmed the problem is caused by ProGuard command line in the file
[Android SDK Installation Directory]\tools\proguard\bin\proguard.bat
Edit the following line will solve the problem:
call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %*
to
call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %1 %2 %3 %4 %5 %6 %7 %8 %9
You can solve this issue easily (with Eclipse Android Developer Tools, Build: v22.0.1-685705) by turn off menu > "Project" > "Build Automatically" while exporting (un)signed Android application. After that, don't forget to turn it on again.
If you have ADT revision 12+, you should update your proguard from 4.4 -> 4.6 (as described here). Also, you should leave ...\bin\proguard.bat file in the orginal form.
Just download it from the web, and copy lib folder from downloaded package to the :
[Android SDK Installation Directory]\tools\proguard\lib
EDIT (new solution):
It looks like the previous solution is only a bypass. I managed to finally fix the problem permanently:
In my case there was a mismatch in android-support-v4 files in my project and in the Facebook project that is referenced in my project.
I found this error by performing Lint Check (Android Tools / Run Lint: Check for Common Errors)
My previous solution:
I've tried any possible solution on this site - nothing helped!!!
Finally I've found an answer here:
https://groups.google.com/forum/#!topic/actionbarsherlock/drzI7pEvKd4
Easy steps:
Go to Project -> uncheck Build Automatically
Go to Project -> Clean... , clean both the library project and your
app project
Export your app as a signed APK while Build Automatically is still
disabled
Here's another scenario, and solution:
If you run into this problem recently after updating the ADT for Eclipse:
In your app project, check for any linked source folders pointing to your library projects (they have names in the form "LibraryName_src").
Select all those projects, right-click, choose "Build Path"->"Remove from Build Path".
Choose "Also unlink the folder from the project", and click "Yes".
Clean, rebuild and redeploy the project.
It seems the reason is that some previous version of ADT linked Library project source folders to the "child" projects, and the current ADT/Dex combination isn't compatible with that solution anymore.
EDIT: this is confirmed by an Android Dev Blog entry, specifically this one - see the 8th paragraph onwards.
Go to Project and then uncheck "Build Automatically".Then try to export the project and the error is gone.
This can also be caused if you have added Android.jar file to your build path, perhaps by an accidental quick fix in Eclipse. Remove it with right clicking Project -> build path -> configure build path -> android.jar, remove.
Simply cleaning the project has worked for me every time this error has come up.
My own and only solution that I found today after four hours of testing all the solutions, is a combination of many solutions provided here:
Delete project from Eclipse
Delete files in \bin and \gen from project folder
Remove references to libraries into .classpath file in root project folder
Restart Eclipse with command line : eclipse -clean
Import project
Right click on project - select Properties > Java Build Path > Libraries and remove everything else than Android XX.Y
Finally clean project, wait for automatic Building or Build it
Launch and now it works! At least for me...
I tried every step at a time and many combinations, but only the succession of all steps at once made it! I hope I won't face this again...
Just for the other people who still have this problem and they have tried the above answers but still getting the error (which was my case), then my solution was to delete the project from Eclipse and re-import it again.
This made the Android library to be added again to my referenced libraries, so now I have two Android JAR files referenced, hence I deleted one of them and now it compiles fine.
Solution: Delete the project from Eclipse IDE and then re-import it again, then check for the above solutions.
Ran into this problem myself today. Cleaning and rebuild did not fix the problem. Deleting and reimporting the project didn't help either.
I finally traced it back to a bad additions to my .class file. I think this was added by the plugin tools when I was trying to fix another problem, removing it got rid of the "Conversion to Dalvik format failed with error 1" build error:
<classpathentry kind="lib" path="C:/dev/repository/android-sdk-windows/platforms/android-3/android.jar">
<attributes>
<attribute name="javadoc_location" value="file:/C:/dev/repository/android-sdk-windows/docs/reference"/>
</attributes>
<accessrules>
<accessrule kind="nonaccessible" pattern="com/android/internal/**"/>
</accessrules>
For me, an extra JAR reference had appeared in my build path. I deleted this, and it works now.
My problem was caused by ADT version 12.0 and ProGuard integration.
This bug is well documented and the solution is in the documentation
Solution is in here
ProGuard command line
Updating Proguard to latest version solved it for me.
My proguard path was C:\Program Files (x86)\Android\android-sdk\tools\proguard\
I downloaded the new version from here
and replaced both bin and lib folders
THANK GOD!
I've dealt with this problem when using Sherlock ActionBar library in my project.
You could do the following step, it's work for me.
Right click to your project, select properties.
A dialog will show up, select 'Java build path' on the left menu.
Remove 'Android dependencies' and 'Android private libraries' on the right panel then click OK
Clean your project (select menu Project --> Clean)
Right click your project, select Android Tools -> Fix project properties
Clean project once again.
Restart your computer
Open eclipse and Export apk
Hope that will help you.
In my case the problem is actually with OpenFeint API project. I have added OpenFeint as library project:
.
It is also added into build path, ADT tools 16 gives error with this sceneario.
Right click on your project and click build path, configure the build path and then see the image and remove your project OpenFeint from here and all is done :)
I found something else. Android uses the /libs directory for JAR files. I have seen the "Conversion to Dalvik format failed with error 1" error numerous times, always when I made a mistake in my JAR files.
Now I upgraded Roboguice to a newer version, by putting the new JAR file in the /libs directory and switching the class path to the new version. That caused the Dalvik error.
When I removed one of the Roboguice JAR files from the /libs folder, the error disappeared. Apparently, Android picks up all JAR files from /libs, regardless of which ones you specify in the Java build path. I don't remember exactly, but I think Android started using /libs by default starting with Android 4.0 (Ice Cream Sandwich, ICS).
In general, it seems that this problem comes when there are unnecessary JAR files in build path.
I faced this problem while working on IntelliJ IDEA. For me it happened because I added JUnit and Mockito libraries which were being compiled at runtime. This needed to be set to "testing" in module properties.
None of previously proposed solutions worked for me. In my case, the problem happened when I switched from referencing a library source code folder to using the library JAR file.
Initially there was an Android library project listed under the Android application project Properties\ Android page\ Library section, and the library compared also in project explorer tree as a link to the library source directory.
In the first place, I just deleted the directory link from the project tree and I added the JAR library to the build path, but this caused the exception.
The correct procedure was (after changing back the build path and putting back the reference to the library source):
properly remove the library source directory link by actually removing the reference from application project Properties\ Android page
adding the library JAR to the application project build path as usual.
None of the listed solutions worked for me.
Here's where I was having a problem:
I added the jSoup external JAR file to my project's path by first putting it in a source folder called "libs", and then right clicking on it, Build Path -> add to build path. This threw the Dalvik conversion error. It said I had "already included" a class from that JAR file. I looked around the project's directory and found that the place where it was "already included" was in fact the bin directory. I deleted the JAR file from the bin directory and refreshed the project in Eclipse and the error went away!
All the solutions above didn't work for me. I'm not using any precompiled .jar. I'm using the LVL and the Dalvik errors where all related to the market licensing library.
The problem got solved by deleting the main project and reimporting (create a new project from existing sources).
I had the same problem and none of these solutions worked.
Finally, I saw in the console that the error was due to duplicated class (one in the existing project, one in the added jar file) :
java.lang.IllegalArgumentException: already added: package/MyClassclass;
[2011-01-19 14:54:05 - ...]: Dx1 error; aborting
[2011-01-19 14:54:05 - ...] Conversion to Dalvik format failed with error 1
So check if you are adding jar with duplicated classes in your project.
If yes, try removing one of them.
It worked for me.
Often for me, cleaning the project DOES NOT fix this problem.
But closing the project in Eclipse and then re-opening it does seem to fix it in those cases...
I ran into this problem but my solution was twofold.
1.) I had to add an Android target version under project -> properties -> Android.
2.) I didn't have all google 'third party add-ons'. Click in AVD SDK manager under available packages -> third-party add-ons -> Google Inc. I downloaded all of the SDKs and that solved my issue.
I am using Android 1.6 and had one external JAR file. What worked for me was to remove all libraries, right-click project and select Android Tools -> *Fix Project Properties (which added back Android 1.6) and then add back the external JAR file.
I ran into this problem because the Android-Maven-plugin in Eclipse was apparently not recognizing transitive references and references referenced twice from a couple of projects (including an Android library project), and including them more than once. I had to use hocus-pocus to get everything included only once, even though Maven is supposed to take care of all this.
For example, I had a core library globalmentor-core, that was also used by globalmentor-google and globalmentor-android (the latter of which is an Android library). In the globalmentor-android pom.xml I had to mark the dependency as "provided" as well as excluded from other libraries in which it was transitively included:
<dependency>
<groupId>com.globalmentor</groupId>
<artifactId>globalmentor-core</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- android-maven-plugin can't seem to automatically keep this from being
included twice; it must therefore be included manually (either explicitly
or transitively) in dependent projects -->
<scope>provided</scope>
</dependency>
Then in the final application pom.xml I had to use the right trickery to allow only one inclusion path---as well as not explicitly including the core library:
<!-- android-maven-plugin can't seem to automatically keep this from being
included twice -->
<!-- <dependency> -->
<!-- <groupId>com.globalmentor</groupId> -->
<!-- <artifactId>globalmentor-core</artifactId> -->
<!-- <version>1.0-SNAPSHOT</version> -->
<!-- </dependency> -->
<dependency>
<groupId>com.globalmentor</groupId>
<artifactId>globalmentor-google</artifactId>
<version>1.0-SNAPSHOT</version>
<exclusions>
<!-- android-maven-plugin can't seem to automatically keep this from
being included twice -->
<exclusion>
<groupId>com.globalmentor</groupId>
<artifactId>globalmentor-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.globalmentor</groupId>
<artifactId>globalmentor-android</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
In my case
project->properties->java build path -> in order and export tab -> uncheck android-support-v4.jar
Just clean the project
If this does not work try the other solutions

Error: Archive for required library cannot be read or is not a valid ZIP file.

I am having trouble setting up the build path of my java project. I am currently in a Co-Op IT position so I am somewhat new to all this. My background is mostly in C++ and I am learning java on the fly. I am also somewhat new to Eclipse (Kepler service release 1).
I am working on a bug on an existing program and need to get the program to build so I can work on it. When I add all of the external .jar files that I know for a fact are the right ones, I am getting this error on two of them :
"Archive for required library: '(location of file)' cannot be read or is not a valid ZIP file"
Two of the other full time guys on my team have gotten the program to run with those exact same .jar files, one running Eclipse Indigo and the other running the same Kepler version as myself. I also was able to open the two .jar files manually and everything appears to be there. After every trial trying to fix this, I have refreshed, cleaned and restarted eclipse. The two other full time guys said they have never seen this error. I would like to get some insight on this from anyone who has any similar experiences so that I don't have to use up much more of their time.
I Had this issue, just fixed by deleting .jar files from Libs directory then copy->paste original Jars again. Then do a complete clean -> rebuild
I got this problem, took help from following link solution
which basically says to
1. delete the corresponding maven download folder
2. maven>update project in eclipse
In my case I deleted hibernate folder, since i was getting error related to hibernate-validator.jar
I had the same error here. What I did to resolve the problem was close and reopen the project.
I got the same problem and found out the root cause is the JDK in my linux shell is set to 1.6, but in the eclipse, the JRE is 1.7.
Using Eclipse without m2e features (Standard Edition) helped me.
Similar problem with Spring toolsuite
Just came across this link that shows a way to get unblocked.
In preferences dialog box go to
Java->Compiler->Building
and change Incomplete build path to "Warning" (from default "Error")
This can be done globally (for all projects), or on a project by project basis.
Check the jar's file permissions/ownership.
I had the same issue on eclipse installed on Linux and fixed it by setting the file permissions right.
In my case ..worked after removing this from spirngrest-servlet.xml file.
<prop key="net.sf.ehcache.configurationResourceName">/Sysehcache.xml</prop>
I think it had to do with default location of maven repository of jar files.
Been at it for 3 days. finally solved it.Hope it helps anyone.Just look for similar think in your spirngrest-servlet.xml file. Good luck.
I just tried the following and it worked:
Close eclipse as there might be some files eclipse is accessing and you won't be able to delete.
Delete all the libraries installed in the maven repositories folder: ".m2/repository"
Open eclipse and update your project(Alt+F5).
What did we just do? : This is possible that the existing libraries in the local repository are erroneous and maven tries to open which it fails in. We have now deleted the already existing library and with the project update, Maven will download the library again which should resolve the issue.
i fixed this by just deleting everything inside of the /Users/username/.m2/repository folder. not the repository folder itself. and then running a mvn clean package in the project folder

Eclipse is not showing compilation errors in project explorer

I am using Eclipse Juno with Java 1.7 and i have created a test project. Now the problem is with project explorer. Project explorer is not showing compilation errors if class have any error.
I cleaned, closed , and rebuild the project but nothing is changed. It is still not showing errors in project explorer.It was working fine with Helios.
As I can see in your project explorer there is a RED exclamation mark over your project name which means there is a problem with the build path in your project. See here for more details.
Check the Build Path of the project by right-clicking the project and selecting Build Path -> Configure Build Path.
One problem I often encountered is different people using different Java SDK and so when the exact SDK is not available on your machine, you need to change to your Java SDK (via JRE System Library -> Alternate JRE). A better way to avoid this problem is to always select the JRE System Library from Workspace default JRE or Execution Environment.
Have you checked Project/Build Automatically?
I had the same problem. I checked the .classpath file of the Eclipse project. It had incorrect value of src so it was pointing to the wrong source of Java files.
My file's incorrect entry:
<classpathentry kind="src" path="src"/>
I changed it to the correct entry:
<classpathentry kind="src" path="source/java"/>
Now, its working :)
You can restore the errors to the package explorer by right clicking on an error in the problems pane and selecting show in and then select package explorer.
Set your build path and java compiler:
Steps:
Right click on the project and go to the properties.
Go to the java build path and set the jre version to the jdk5 or more. (which ever you have to your system).
Go to the java compiler and set java version to the compatible with jre (which ever you set in java build path).
After refreshing the project you may get the compilation error.
Set your Errors/Warnings:
Steps:
1) Right click on the project and go to the properties.
2) Select Java Compiler -> Errors/Warnings.
3) Check the "Enable project specific settings"
In eclipse you can right-click on a project and go Maven-->Update Maven
Project and this will tell eclipse to update all of its local project
settings (e.g. source and build paths) based upon the current pom.xml.
You must check the build Path configuration to point for the appropriate /src sources java folders, perform a clean up of the eclipse project as well as a maven clean.
I had the same issue.
I have faced similar kind of problem in Eclipse Photon.
I have cleaned, updated and build the project but nothing was working. Then I figured out that I have disabled problem reporting in preferences.
Here is what I did to resolve the issue :
Preferences-->>Editor--> Checked report problems as you type checkbox
Go to the eclipse project -> check the Build Automatically. It will solve the problem. I had the same issue and resolved like this.
Check your class package, it should be under src/main/java, if package differs from that, the compiler will not be able to read class and will not show compilation errors.
I had created a nested project and imported it by doing a refresh, but to get it to be acknowledged as a project that needed to be compiled, I had to also import it as a project:
Then, I also had to double click on one of the compilation errors in the "Problems" window to get the errors to also be highlighted in the source code file itself:
I had AspectJ enabled on my project, and that was the source of the issue.
So:
Right click on my project, AspectJ Tools, Remove AspectJ Compatibility. Then add it again with Right click and then Configuration and AspectJ

Jar Mismatch Found 2 versions of android-support-v4.jar in the dependency list

I am trying to create 2 versions of an Android app (free/paid). I have an Android Library that contains files common to both. I created a new Android project and am trying to use the Library but get the error below:
Found 2 versions of android-support-v4.jar in the dependency list,
but not all the versions are identical (check is based on SHA-1 only at this time).
All versions of the libraries must be the same at this time.
Versions found are:
Path: /Users/Zaheer/Developer/App Free/libs/android-support-v4.jar
Length: 349252
SHA-1: 612846c9857077a039b533718f72db3bc041d389
Path: /Users/Zaheer/Developer/App Library/libs/android-support-v4.jar
Length: 337562
SHA-1: 27c24d26e4c5d57976e6926367985548678e913c
Any ideas on how to resolve this? I've been playing with the build path to no success.
Any ideas on how to resolve this?
Delete one.
I've been playing with the build path to no success.
Step #1: Undo all that. If you are messing with the build path, on R16 or higher version of the ADT plugin for Eclipse, you're doing it wrong.
Step #2: Pick one of those two versions of the JAR, or pick the one from the "extras" area of your SDK installation.
Step #3: Put the right JAR in App Library.
Step #4: Delete the one from App Free, since it will pick up that JAR from App Library.
You are welcome to instead have the same actual JAR file in both spots (App Free and App Library), though that just takes up extra space for no reason.
Delete android-support-v4.jar from App Free
Add the same file from App Library to App Free
Above solutions mostly solve the problem. after using these solutions and problem persists. Then
GO to project folder -> libs-> and delete "android-support-v4.jar"
Hoping it would solve your problem as it solved my problem.
There are some scenarios where you have multiple library projects having the the android-support-v4.jar in their libs and build paths and your project has a dependency towards both of them. Say for example in my case I have the following library projects in my workspace,
libfacebook
libsherlockactionbar
Both these projects are independent and my project.properties looks like the following,
# Project target.
target=android-17
android.library.reference.1=../libfacebook
android.library.reference.2=../libsherlockactionbar
When I build my project, I get a jar mismatch problem having duplicate references to two copies of the same file. What I did to solve this issue is a bit of trickery. I created a new library project named libcommons as a parent to all the other library projects in my workspace, including libfacebook and libsherlockactionbar. Then I removed the support library from all other projects and kept only one copy inside libcommons's libs folder. Then I have added libcommons as a reference to all my other library projects. Once cleaned my workspace, everything works like a charm.
This is a more elegant fix than deleting and adding files!
You just need to :
Right Click the project App Free
Go To "Android Tools" > "Add Support Library"
Approve the permissions and let it update the library
Repeat this process for the project App Library
The Android Support Library will then be in sync (:
VERY SIMPLE SOLUTION
A very simple solution worked for my case, just copy the same (android-support-v4.jar) jar file to all the projects. There will be no more conflict.
1 Copy the jar file android-support-v4.jar from libs folder of any one project.
2 Delete the jar file android-support-v4.jar from second project's libs folder which is already existing.
3 Paste the newly copied jar file of first project to libs folder of second project.
The jar mismatch issue will be resolved by now.
Just copy the library from one of the projects to the other one. Maybe the timestamp needs to be the same on both.
Resolution:
Right click on 'free' project > Android Tools > Add Support Library.
Do the same thing on 'paid' project.
Clean all projects
Check if there are irrelevant projects open for you, because that was the case for me, it seemed one of the JAR files was related to a different project, which I wasn't working with, so I just closed that project, did a clean build of the project I'm working on and didn't have the problem anymore! Hope this helps someone!
Use same jar while adding external jars in both library and project
well.. it works for me:
Go to
Project folder > libs
then, delete "android-support-v4.jar"
Then
project > Clean
It will work!
I just had this issue, but instead of deleting the conflicting android-support-v4.jar I just renamed it to android-support-v4_PROJECT.jar, which removed the conflict.
If you are wondering how to rename a file in Eclipse, you just need to highlight the file and press F2.
You just need to have exactly the same android-support-v4.jar checksum on each of your projects.
For this, you can copy/past one of them in all of your conflicting projects / library.
Nothing else to do, clean and enjoy :)
May be you open 2 project same time (both using android-support-v4.jar) . I close 1 project and every thing ok

Categories

Resources