Archive

Posts Tagged ‘sdk’

Eclipse ADT : Unable to get system library for the project / Conversion to Dalvik format failed with error 1

August 14, 2011 2 comments

Google has provided the ADT plugin for Eclipse which makes the job of creating / testing android applications substantially easier that would have been if we had to use only the command line tools provided with the Android SDK. However I have been facing a strange issue repeatedly for the last couple of days. After restarting my system when I start Eclipse and navigate over to my android project, it shows error as shown in the figure below.


I had no idea as to why this happened. I opened the build path for the project and the message shown there was “Unable to get system library for the project

I tried adding the android.jar manually to the project by clicking on the “Add External Jars” button. After adding the jar and cleaning the project, the errors for java.lang.Object not found did vanish. But another problem appeared. The error was “Conversion to Dalvik format failed with error 1“. I searched the Internet forums far and wide but I guess that the error message that I received was generated a bit too often and under a wide variety of circumstances. I tried cleaning the project, restarting eclipse etc. Finally on a certain forum I found the mention of checking the .classpath file that Eclipse creates. And voila!!  the source of the problem was found !! The below listing shows the .classpath file for the project after adding the android.jar manually through the Eclipse Build Path window.

<!--?xml version="1.0" encoding="UTF-8"?--><?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="lib" path="/media/Data/Development/android-sdk-linux_86/platforms/android-8/android.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

I compared this to the entry of a new project that I created in Eclipse which was as follows.

<!--?xml version="1.0" encoding="UTF-8"?--><?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="output" path="bin"/>
</classpath>

Comparing the two, the solution was easy to identify. I replaced the third line in the .classpath file about the “lib” and replaced it with the corresponding line in the second file.

And it works now !!

As of the time of this writing I have not been able to understand why this happens everytime I restart my eclipse / system and hence I have to replace the classpath entry everytime I start Eclipse. But atleast it works. Hope this helps you. And incase it does, please share it with others.

So after starting eclipse if you see that there are problems relating to java.lang.Object not found, open the .classpath and edit the line as shown above.

Advertisements