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
Related
While debugging a java app in eclipse I receive a "Source not found" error in two cases:
Stepping in to a file in a different project which is already imported
Stepping in to a file in an installed maven repository
The files are there, but eclipse won't step into them, instead it shows a button to "attach source"
I tried attaching (which opened a dialog to define a variable?!) and eclipse did jump to the file, but the debugger could not inspect any variables there. Also manually attaching the source for each dependency isn't practical, as in my case there are thousands of dependency files.
Why is this happening, and how can it be resolved?
Just 3 steps to configuration Eclipse IDE:
Note: After updating the Source Lookup paths, you'll have to stop and restart your debug session. Otherwise, the file with the missing source will continue to show "missing source".
Edit Source Lookup
Select the Edit Source Lookup... command [ Edit Source Lookup ] to open the Source Path Dialog, which allows you to make changes to the source lookup path of the selected debug target.
IMPORTANT Restart Eclipse after this last step.
Eclipse debugging works with the class actually loaded by the program.
The symptoms you describe sounds like the class in question was not found in the project, but in a distribution jar without debug info found before the project you are working with.
This can happen for several reasons but have a look at the location where the classes showing this behaviour is found (look in the navigation pane to identify it). You will most likely need to change the build path of the project to avoid using this jar and have the JVM use the project instead.
EDIT: Note that as of 2018 it is common to use a build framework like Maven, where the build path is managed by the m2e plugin so this problem should be very less frequent than when the question was asked. If you use Maven and m2e, make sure to enable Preferences / Maven / "Download Artifact Sources" or right-click the project, Maven / "Download Sources".
The symptoms perfectly describes the case when the found class doesn't have associated (or assigned) source.
You can associate the sources for JDK classes in Preferences > Java > Installed JRE. If JRE (not JDK) is detected as default JRE to be used, then your JDK classes won't have attached sources. Note that, not all of the JDK classes have provided sources, some of them are distributed in binary form only.
Classes from project's build path, added manually requires that you manually attach the associated source. The source can reside in a zip or jar file, in the workspace or in the filesystem. Eclipse will scan the zip, so your sources doesn't have to be in the root of the archive file, for example.
Classes, from dependencies coming from another plugins (maven, PDE, etc.). In this case, it is up to the plugin how the source will be provided.
PDE will require that each plugin have corresponding XXX.source bundle, which contains the source of the plugin. More information can be found here and here.
m2eclipse can fetch sources and javadocs for Maven dependencies if they are available. This feature should be enabled m2eclipse preferences (the option was named something like "Download source and javadocs".
For other plugins, you'll need to consult their documentation
Classes, which are loaded from your project are automatically matched with the sources from the project.
But what if Eclipse still suggest that you attach source, even if I correctly set my classes and their sources:
This almost always means that Eclipse is finding the class from different place than you expect. Inspect your source lookup path to see where it might get the wrong class. Update the path accordingly to your findings.
Eclipse doesn't find anything at all, when breakpoint is hit:
This happens, when you are source lookup path doesn't contain the class, which is currently loaded in the runtime. Even if the class is in the workspace, it can be invisible to the launch configuration, because Eclipse follows the source lookup path strictly and attaches only the dependencies of the project, which is currently debugged.
An exception is the debugging bundles in PDE. In this case, because the runtime is composed from multiple projects, which doesn't have to declare dependencies on one another, Eclipse will automatically find the class in the workspace, even if it is not available in the source lookup path.
I cannot see the variables when I hit a breakpoint or it just opens the source, but doesn't select the breakpoint line:
This means that in the runtime, either the JVM or the classes themselves doesn't have the necessary debug information. Each time classes are compiled, debug information can be attached. To reduce the storage space of the classes, sometimes this information is omitted, which makes debugging such code a pain. Your only chance is to try and recompile with debug enabled.
Eclipse source viewer shows different lines than those that are actually executed:
It sometimes can show that empty space is executed as well. This means that your sources doesn't match your runtime version of the classes. Even if you think that this is not possible, it is, so make sure you setup the correct sources. Or your runtime match your latest changes, depending on what are you trying to do.
From http://www.coderanch.com/t/587493/vc/Debugging-Eclipse-Source
"When running in debug mode, right click on the running thread (in threads tab) and select Edit Source Lookup. At this point, you should be able to add the necessary project/jar which contains your source code."
I added my current project in this way, and it solved my problem
I had similar problem with my eclipse maven project. I fought with this issue quite a long time then I tried to rebuild project with
mvn clean eclipse:eclipse
and it helped.
Note: Using this approach will confuse the m2e plugin since the two approaches are very different. m2e adds a virtual node to your project called "Maven Dependencies" and asks Maven to add all dependencies there.
mvn eclipse:eclipse, on the other hand, will create a lot of individual entries in the file .classpath. Eclipse will handle them as if you manually added JARs to your project.
Unless you know how the classpath in Eclipse works, this approach is not recommended.
I was facing the same issue,I followed the bellow steps.
Window => Preferences => Java => Installed JREs,
You see in the above screen Jre1.8.0_12 is selected.
select the JRE you are using and click Edit. Now You should see the bellow screen.
Click on the directory, browse for Jdk, It should look like bellow screen.
click ok, and its done
I had the problem that my Eclipse was not debugging the source code of my project. I was getting a blank page with "Source code node found".
Please click the Attach source code button. Then delete the "default" folder then click add and go to your project location and attach. This worked for me
Remove the existing Debug Configuration and create a new one. That should resolve the problem.
None of the mentioned answer worked for me.
To resolve this issue i have to follow bellow steps:
Right click on Java HotSpot(TM) 64 Bit server.
Select "Edit Source Lookup".
Click on "Add".
Select "File System Directory" instead of Java project.
Select Root directory of your project.
Check "Search Subfolders".
Click Ok ok ok.
Thanks.
Click -> Edit Source Lookup Path
after then
Click -> Add finally select Java project and select project path.
Source: https://www.youtube.com/watch?v=IGIKPY6q1Qw
In my case, even after Editing source lookup and Adding project, it didn't worked. I configured the Build path of the project.
After that, I selected JRE System Library and it worked.
Evidently, Eclipse does not automatically know where the source code for the dependent jars are. It is not clear why debugger could not inspect variables once the source was attached. One possibility is incorrect/incompatible source.
Assuming you have a maven project and the sources of the dependencies are downloaded and available in the local repository, you may want to install m2eclipse, the maven eclipse plugin and see if that helps in addressing your issue.
You might have source code of a dependency accessible to Eclipse. But Eclipse does not know for source code for code that is dynamically loaded. E.g. through Maven.
In case of Maven, I recommend that you use run-jetty-run plugin:
http://code.google.com/p/run-jetty-run/
As a workaround you can also connect to a running JVM with the debugger and you will see the code.
Alternatively you can use Dynamic Source Lookup plugin for Eclipse from here:
https://github.com/ifedorenko/com.ifedorenko.m2e.sourcelookup
Unfortunately it didn't helped me as it has issues with Windows paths with spaces.
I have filled an enhancement request on Eclipse Bugzilla and if you agree this issue "Source not found" should vanish forever, please vote for it here:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=384065
Thanks!
Sasa
In my case in "Attach Source", I added the other maven project directory in the "Source Attachment Configuration" panel. Adding the latest version jar from the m2 repository din't work. All the classes from the other maven project failed to open.
Here test was my other maven project containing all the java sources.
I had the very same problem. In my case, I've disabled Window-Preferences-Java-Debug [Suspend execution on uncaught exceptions]. Then, the console showed me the correct error: my MySql user hadn't privileges to access the database. According to this topic.
Info: This is a possible solution, when you use maven (pom.xml) with couple of projects.
If you are working with maven, make sure what version you are taking inside the according pom.xml (e. g. 1.0.1-SNAPSHOT ).
It might be possible that your code is up-to-date, but your pom.xml dependencies are still taking the old JAR's/Snapshots (with the old code).
Finding the problem:
Try to debug the according file.
Therefore, set a breakpoint in the relevant code area.
When "source not found" appears, make sure to bind in the right project (where the .java file can be found).
The compile .class file opens up in the IDE editor.
Click "Link with Editor" to find the according JAR/Snapshot.
Now make sure that this JAR is the most recent one. Possibly there is a newer one. In that case, write the most recent version number in the pom.xml.
Then do a maven update and build (e. g. "mvn clean install -U") in the right project directory.
If you are on eclipse or STS please install and Use GC(GrepCode Plugin) ,some time you don't need to attach the source .zip file into your project path so GrepCode works fine for you.
I've had a related issue in connection with Glassfish server debugging in Eclipse.
This was brought about by loading the source code from a different repository (changing from SVN to GitHub). In the process, the wrong compiled classes were used by the Glassfish server and hence, the source and run time would be out of sync with break points appearing on empty lines.
To solve this, rename or delete the top folder of the classes directory and Glassfish will recreate the whole class directory tree including updating the class files with the correctly compiled version.
The classes directory is located in: /workspace/glassfish3122eclipsedefaultdomain/eclipseApps/< your Web Application>/WEB-INF/classes
In my case with tomcat projects I have checked project here:
Window - Preferences - Tomcat - Source Path - Add java projects to source path
In my case the Maven version of the other referenced project didn't match the version of the test project. Once they were the same, the problem disappeared.
When running in debug mode, click Edit Source Lookup after suspended from thread. At this point, we should be able to add the necessary project/jar which contains your source code.
After I added my current project in this way, and it solved my problem. Thanks
If you want to attach source code to any JAR by auto-downloading, try using this Eclipse plugin Java Source Attacher
I had this problem while working on java code to do process on a excel file containing a data set, then convert it to .csv file, i tried answers to this post, but they did not work.
the problem was the jar files themselves. after downloading needed jar files one by one(older releases) and add them to my project, "source not found" error vanished.
maybe you can check your jar files.
hope this would help.
this worked for me
right click on project -> Properties -> Deployment Assembly -> add your jar
Go to Debug configuration in eclipse and use below goal to run your application.
-Dmaven.surefire.debug
e.g
-Dmaven.surefire.debug exec:java
Well, here's what worked for me. I tried every possible solution on StackOverflow that there was. I tried changing my source location in the debug menu, I installed the m2e Eclipse plugin, I changed from embedded Maven, and I installed the run-jetty-run and nothing worked. Now, I will caveat that I was not trying to view an external person's source code, I just wanted to see my OWN code, but every time I "stepped in" to my methods that I wrote that were in MY project, I got the "Source now found" error.
After finally asking an expert, my issue was that the first thing Eclipse was doing was calling a ClassLoader, which you can see from the debug stack. All I had to do was F6 (step over) and then it took me back to my original call and then F5 (step in). And there was my code. Sigh...such a simple fix but an hour wasted.
For beginners,
There is a possibility that the jar file is a part of the project which you have not yet included in the Eclipse workspace.
For that, you need to know the project name of the jar file.
Say for example, its abc-18.0.0-SNAPSHOT.jar, it means that the project you are supposed to include in your workspace is abc.
I had the same issue with eclipse 2019-03 (4.11.0) and I was only able to solve this by doing the debugging via remote debugging instead of directly launching it in debug mode.
Attach source -> Add -> External Archive -> select the jar -> open -> done
the catch is look for the sources jar and attach this jar.
for example the jar ends with "-sources" Stax2-api-3.4.1-sources
sometimes these thing happens because of the version also like if you are using latest
version in that case it may arise try to use older version it will work.
While debugging a java app in eclipse I receive a "Source not found" error in two cases:
Stepping in to a file in a different project which is already imported
Stepping in to a file in an installed maven repository
The files are there, but eclipse won't step into them, instead it shows a button to "attach source"
I tried attaching (which opened a dialog to define a variable?!) and eclipse did jump to the file, but the debugger could not inspect any variables there. Also manually attaching the source for each dependency isn't practical, as in my case there are thousands of dependency files.
Why is this happening, and how can it be resolved?
Just 3 steps to configuration Eclipse IDE:
Note: After updating the Source Lookup paths, you'll have to stop and restart your debug session. Otherwise, the file with the missing source will continue to show "missing source".
Edit Source Lookup
Select the Edit Source Lookup... command [ Edit Source Lookup ] to open the Source Path Dialog, which allows you to make changes to the source lookup path of the selected debug target.
IMPORTANT Restart Eclipse after this last step.
Eclipse debugging works with the class actually loaded by the program.
The symptoms you describe sounds like the class in question was not found in the project, but in a distribution jar without debug info found before the project you are working with.
This can happen for several reasons but have a look at the location where the classes showing this behaviour is found (look in the navigation pane to identify it). You will most likely need to change the build path of the project to avoid using this jar and have the JVM use the project instead.
EDIT: Note that as of 2018 it is common to use a build framework like Maven, where the build path is managed by the m2e plugin so this problem should be very less frequent than when the question was asked. If you use Maven and m2e, make sure to enable Preferences / Maven / "Download Artifact Sources" or right-click the project, Maven / "Download Sources".
The symptoms perfectly describes the case when the found class doesn't have associated (or assigned) source.
You can associate the sources for JDK classes in Preferences > Java > Installed JRE. If JRE (not JDK) is detected as default JRE to be used, then your JDK classes won't have attached sources. Note that, not all of the JDK classes have provided sources, some of them are distributed in binary form only.
Classes from project's build path, added manually requires that you manually attach the associated source. The source can reside in a zip or jar file, in the workspace or in the filesystem. Eclipse will scan the zip, so your sources doesn't have to be in the root of the archive file, for example.
Classes, from dependencies coming from another plugins (maven, PDE, etc.). In this case, it is up to the plugin how the source will be provided.
PDE will require that each plugin have corresponding XXX.source bundle, which contains the source of the plugin. More information can be found here and here.
m2eclipse can fetch sources and javadocs for Maven dependencies if they are available. This feature should be enabled m2eclipse preferences (the option was named something like "Download source and javadocs".
For other plugins, you'll need to consult their documentation
Classes, which are loaded from your project are automatically matched with the sources from the project.
But what if Eclipse still suggest that you attach source, even if I correctly set my classes and their sources:
This almost always means that Eclipse is finding the class from different place than you expect. Inspect your source lookup path to see where it might get the wrong class. Update the path accordingly to your findings.
Eclipse doesn't find anything at all, when breakpoint is hit:
This happens, when you are source lookup path doesn't contain the class, which is currently loaded in the runtime. Even if the class is in the workspace, it can be invisible to the launch configuration, because Eclipse follows the source lookup path strictly and attaches only the dependencies of the project, which is currently debugged.
An exception is the debugging bundles in PDE. In this case, because the runtime is composed from multiple projects, which doesn't have to declare dependencies on one another, Eclipse will automatically find the class in the workspace, even if it is not available in the source lookup path.
I cannot see the variables when I hit a breakpoint or it just opens the source, but doesn't select the breakpoint line:
This means that in the runtime, either the JVM or the classes themselves doesn't have the necessary debug information. Each time classes are compiled, debug information can be attached. To reduce the storage space of the classes, sometimes this information is omitted, which makes debugging such code a pain. Your only chance is to try and recompile with debug enabled.
Eclipse source viewer shows different lines than those that are actually executed:
It sometimes can show that empty space is executed as well. This means that your sources doesn't match your runtime version of the classes. Even if you think that this is not possible, it is, so make sure you setup the correct sources. Or your runtime match your latest changes, depending on what are you trying to do.
From http://www.coderanch.com/t/587493/vc/Debugging-Eclipse-Source
"When running in debug mode, right click on the running thread (in threads tab) and select Edit Source Lookup. At this point, you should be able to add the necessary project/jar which contains your source code."
I added my current project in this way, and it solved my problem
I had similar problem with my eclipse maven project. I fought with this issue quite a long time then I tried to rebuild project with
mvn clean eclipse:eclipse
and it helped.
Note: Using this approach will confuse the m2e plugin since the two approaches are very different. m2e adds a virtual node to your project called "Maven Dependencies" and asks Maven to add all dependencies there.
mvn eclipse:eclipse, on the other hand, will create a lot of individual entries in the file .classpath. Eclipse will handle them as if you manually added JARs to your project.
Unless you know how the classpath in Eclipse works, this approach is not recommended.
I was facing the same issue,I followed the bellow steps.
Window => Preferences => Java => Installed JREs,
You see in the above screen Jre1.8.0_12 is selected.
select the JRE you are using and click Edit. Now You should see the bellow screen.
Click on the directory, browse for Jdk, It should look like bellow screen.
click ok, and its done
I had the problem that my Eclipse was not debugging the source code of my project. I was getting a blank page with "Source code node found".
Please click the Attach source code button. Then delete the "default" folder then click add and go to your project location and attach. This worked for me
Remove the existing Debug Configuration and create a new one. That should resolve the problem.
None of the mentioned answer worked for me.
To resolve this issue i have to follow bellow steps:
Right click on Java HotSpot(TM) 64 Bit server.
Select "Edit Source Lookup".
Click on "Add".
Select "File System Directory" instead of Java project.
Select Root directory of your project.
Check "Search Subfolders".
Click Ok ok ok.
Thanks.
Click -> Edit Source Lookup Path
after then
Click -> Add finally select Java project and select project path.
Source: https://www.youtube.com/watch?v=IGIKPY6q1Qw
In my case, even after Editing source lookup and Adding project, it didn't worked. I configured the Build path of the project.
After that, I selected JRE System Library and it worked.
Evidently, Eclipse does not automatically know where the source code for the dependent jars are. It is not clear why debugger could not inspect variables once the source was attached. One possibility is incorrect/incompatible source.
Assuming you have a maven project and the sources of the dependencies are downloaded and available in the local repository, you may want to install m2eclipse, the maven eclipse plugin and see if that helps in addressing your issue.
You might have source code of a dependency accessible to Eclipse. But Eclipse does not know for source code for code that is dynamically loaded. E.g. through Maven.
In case of Maven, I recommend that you use run-jetty-run plugin:
http://code.google.com/p/run-jetty-run/
As a workaround you can also connect to a running JVM with the debugger and you will see the code.
Alternatively you can use Dynamic Source Lookup plugin for Eclipse from here:
https://github.com/ifedorenko/com.ifedorenko.m2e.sourcelookup
Unfortunately it didn't helped me as it has issues with Windows paths with spaces.
I have filled an enhancement request on Eclipse Bugzilla and if you agree this issue "Source not found" should vanish forever, please vote for it here:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=384065
Thanks!
Sasa
In my case in "Attach Source", I added the other maven project directory in the "Source Attachment Configuration" panel. Adding the latest version jar from the m2 repository din't work. All the classes from the other maven project failed to open.
Here test was my other maven project containing all the java sources.
I had the very same problem. In my case, I've disabled Window-Preferences-Java-Debug [Suspend execution on uncaught exceptions]. Then, the console showed me the correct error: my MySql user hadn't privileges to access the database. According to this topic.
Info: This is a possible solution, when you use maven (pom.xml) with couple of projects.
If you are working with maven, make sure what version you are taking inside the according pom.xml (e. g. 1.0.1-SNAPSHOT ).
It might be possible that your code is up-to-date, but your pom.xml dependencies are still taking the old JAR's/Snapshots (with the old code).
Finding the problem:
Try to debug the according file.
Therefore, set a breakpoint in the relevant code area.
When "source not found" appears, make sure to bind in the right project (where the .java file can be found).
The compile .class file opens up in the IDE editor.
Click "Link with Editor" to find the according JAR/Snapshot.
Now make sure that this JAR is the most recent one. Possibly there is a newer one. In that case, write the most recent version number in the pom.xml.
Then do a maven update and build (e. g. "mvn clean install -U") in the right project directory.
If you are on eclipse or STS please install and Use GC(GrepCode Plugin) ,some time you don't need to attach the source .zip file into your project path so GrepCode works fine for you.
I've had a related issue in connection with Glassfish server debugging in Eclipse.
This was brought about by loading the source code from a different repository (changing from SVN to GitHub). In the process, the wrong compiled classes were used by the Glassfish server and hence, the source and run time would be out of sync with break points appearing on empty lines.
To solve this, rename or delete the top folder of the classes directory and Glassfish will recreate the whole class directory tree including updating the class files with the correctly compiled version.
The classes directory is located in: /workspace/glassfish3122eclipsedefaultdomain/eclipseApps/< your Web Application>/WEB-INF/classes
In my case with tomcat projects I have checked project here:
Window - Preferences - Tomcat - Source Path - Add java projects to source path
In my case the Maven version of the other referenced project didn't match the version of the test project. Once they were the same, the problem disappeared.
When running in debug mode, click Edit Source Lookup after suspended from thread. At this point, we should be able to add the necessary project/jar which contains your source code.
After I added my current project in this way, and it solved my problem. Thanks
If you want to attach source code to any JAR by auto-downloading, try using this Eclipse plugin Java Source Attacher
I had this problem while working on java code to do process on a excel file containing a data set, then convert it to .csv file, i tried answers to this post, but they did not work.
the problem was the jar files themselves. after downloading needed jar files one by one(older releases) and add them to my project, "source not found" error vanished.
maybe you can check your jar files.
hope this would help.
this worked for me
right click on project -> Properties -> Deployment Assembly -> add your jar
Go to Debug configuration in eclipse and use below goal to run your application.
-Dmaven.surefire.debug
e.g
-Dmaven.surefire.debug exec:java
Well, here's what worked for me. I tried every possible solution on StackOverflow that there was. I tried changing my source location in the debug menu, I installed the m2e Eclipse plugin, I changed from embedded Maven, and I installed the run-jetty-run and nothing worked. Now, I will caveat that I was not trying to view an external person's source code, I just wanted to see my OWN code, but every time I "stepped in" to my methods that I wrote that were in MY project, I got the "Source now found" error.
After finally asking an expert, my issue was that the first thing Eclipse was doing was calling a ClassLoader, which you can see from the debug stack. All I had to do was F6 (step over) and then it took me back to my original call and then F5 (step in). And there was my code. Sigh...such a simple fix but an hour wasted.
For beginners,
There is a possibility that the jar file is a part of the project which you have not yet included in the Eclipse workspace.
For that, you need to know the project name of the jar file.
Say for example, its abc-18.0.0-SNAPSHOT.jar, it means that the project you are supposed to include in your workspace is abc.
I had the same issue with eclipse 2019-03 (4.11.0) and I was only able to solve this by doing the debugging via remote debugging instead of directly launching it in debug mode.
Attach source -> Add -> External Archive -> select the jar -> open -> done
the catch is look for the sources jar and attach this jar.
for example the jar ends with "-sources" Stax2-api-3.4.1-sources
sometimes these thing happens because of the version also like if you are using latest
version in that case it may arise try to use older version it will work.
I have been successfully using android-support-v7-appcompat library for last few months in my app to support action bar in older devices. Recently I have downloaded the Android 4.4(kitkat) updates with system image and SDK platform from the SDK Manager. I also added targetSdkVersion to "19" in manifest file. But my project was showing error as 'android-support-v7-appcompat jar mismatch. Fix your dependaecies.' Then I added the jar from /extras/android/support/.... to the project as an external jar using build path menu > add external jar. Now there is no error in the project and android-support-v7-appcompat.jar & android-support0v4.jar file is showing twice under 'Referenced Libraries' folder and also once under 'libs' folder. The project is not showing error and running, but crashing in different activities.
Previously I imported the android-support-v7-appcombat library as an external project in the workplace. I can see error in that project. Please suggest what should I do now. Also, android-support-v7-appcompat.jar umder Android Dependencies in Java Build Path showing error.
The error I see is:
Found 2 versions of android-support-v7-appcompat.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: C:\<project hierarchy>\libs\android-support-v7-appcompat.jar
Path: C:\Users\....\sdk\extras\android\support\v7\appcompat\libs\android-support-v7-appcompat.jar
Jar mismatch! Fix your dependencies
After getting idea from different forum, I removed all the android-support-v7-appcompat libraries from different places, and imported android-v7 support library again in the project. Still it's showing error. Should I also delete android-support-v4 libraries from buildpath and libs/private librariry/referenced library folders?
This error occurs when there are multiple and different instances of the same library are found in the same project, or libraries used by it. A very simple way to resolve this is use the common lib at both the places. To do so:
Just copy your C:\Users....\AppData\Local\Android\android-studio\sdk\extras\android\support\v7\appcompat\libs\android-support-v7-appcompat.jar
and paste it in your libs folder, replace the old one with this. Clean the project, and it shall compile now..
Edit 1:
Basically the idea is if you are using the same libraries, it shall be the common jar, or the same jar.
In your case if you are using the appv7 as an external project, please go to libs folder of your project copy android-support-v4.jar, and paste into the libs of android-support-v7-appcompat project.
Also, make sure if there are other external jars or support libraries used by you, they shall be the similar jars in all the projects you are using.
I hope it helps!
I had exactly the same problem after installing all the updates mentioned in the question. I am sure there are different ways to solve this problem. Here is the way I used:
Previously, when an activity was created, the following project was automatically generated by the wizard:
androi-support-v7-appcompat and this project was added to the build path.
After all the updates, the following equivalent is generated when an activity is created:
appcompat_v7 with the jars of the same names.
I deleted androi-support-v7-appcompat and made sure the projects use appcompat_v7 to replace androi-support-v7-appcompat in their build paths. This made hundreds of errors generated by the duplicates go away.
I am glad that i finally found the answer. I was encountering the same problem again and again and i was like fed up.
Here is the answer to your question.
whenever you get such an error just don't touch anything other than libs folder. Just go directly into the libs folder and right away delete the android-support-v4.jar. and clean build your project. You will be relieved to get rid of errors.
Hope its useful to you.
Keep coding..
I have actually figured out the solution by trying different options suggested from different forum. I had manually change the android-support-v7-appcompat project's(which was added as an external project) project.properties file and had to set 'target=android-19'.
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
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.