ChatGPT解决这个技术问题 Extra ChatGPT

"Unable to get system library for project" after I upgraded to Android SDK 2.3 and ADT 8.0

Today I upgraded to Android SDK 2.3 and I also upgraded the Eclipse Plugin Androi Developer Tools 8.0 (from 0.9.9). I also upgraded my Java Development Kit to 1.6_22.

Now in Eclipse I get many errors in all my Android projects.

The error messages are like:

The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files.

How can I fix this so I can use my Android projects again?

In the Build Path for these projects, I don't have any references to an android.jar but a message:

Unable to get system library for project


M
Michael Celey

For me, the problem was that in the Project settings - Android tab, I had no Android version selected.


For me too, but with the addition that selecting a version in the Androids simply unset itself after reopening the preferences.
This is held under Project/Properties (not Settings) on my version of Eclipse. The solution (changing Android 4.3 Build Target from unchecked to checked) worked for me, but I don't understand how it became unchecked - the project worked fine earlier and seemed to stop working without any significant change.
I had a target selected, out of the three I'd installed, but selected a different one anyway, applied, then selected the original one and applied. then build. it fixed for me. just like Iker Martin's answer
Worked for me too on Android 6.0
C
CommonsWare

That is rather difficult to answer, given the limited information you have supplied. Here are some suggestions:

Make sure that an appropriate android.jar is in your build path, since that is where java.lang.Object would come from.

Do a Project > Clean, to make sure you have 1.6 .class files, in case that is part of the problem.

Try creating a new project from scratch and see if that works.


The android.jar seems to be in my Build path. I have already tried with Clean but it doesn't help. I get the same errors when I create new projects.
If I look in the Properties for my project, under "Java Build Path" there is a message: Unable to get system library for project. I think this is the problem, but I don't know how to fix it.
@Jonas: Go into Window > Preferences > Android and make sure your SDK is still configured with the appropriate directory.
@Jonas: You might get that if you have your project configured for some target that you no longer have on the system (e.g., you removed it as part of your round of upgrades). In the project properties dialog, go into the Android area and make sure you have a valid target checked.
I had this same problem and I solved it with @CommonsWare comment (the 3rd one).
M
Mark

I had this problem even though I had a valid target selected. I fixed it by changing to a different target, applying changes and then changing back. That seems to have sorted it.


Yes, this actually re-created the entry for (in my case) Android 2.2 in my Java Build Path, which had been replaced by "unable to get system library for the project" after I installed a number of items. Now everything works as before.
I
Iker Martin

Project->Properties->Android : Select another Android Target (in my case Android 4.0.3) -> Apply changes. THEN select again your default Android Target, and that is all.

Hope this help.


Thanks, it works. Somehow it lost the path to android.jar, just uncheck and check again , it will work
J
Jim Payne

This problem was caused for my old projects on a new machine that did not have an older Android SDK installed.

To fix, simply go into project.properties and observe your old version number:

# Project target.
target=Google Inc.:Google APIs:3

Simply update the version number, like so:

# Project target.
target=Google Inc.:Google APIs:7

You will find that Eclipse then picks up the right SDK version and starts working.


Worked for me. The project was referencing SDK 9 (which wasn't installed). When I edited the android version in the UI, the checkboxes wouldn't stay checked. Editing project.properties fixed things and allowed me to select the correct SDK version.
Z
Zennichimaro

No need to create a new project from scratch. If "Fix Project Properties" or "Add Library > Android Classpath Container" does not work, "project.properties" file might be missing in the root of your project folder. Add that file and set the Android target in the Project properties, re-add the Android Library, Fix Project Properties again, Android System Library should now be included in your project. Rebuilt, and you are good to go!

From my personal experience. For self documenting as well, since this happens quite often on me:

Eclipse Helios SR2
Android SDK R.20
Android NDK R8b
OSX 10.7.4

J
James A Mohler

In my case the issue was related with the missing library path from the properties>android>library.

I cleared and re-entered the library paths in project.properties file


A
Anthony De Souza

Had EXACT issue as the original Question! Had not done anything but close my project/Eclipse and was startled by all the errors upon reopening.

In my case I only needed to do was change/switch workspaces. o_O When I reselected my original workspace I then found everything was resolved and working again!


I also just closed and then reopened the project then everything worked.
z
zahid

Please see your .classpath file, and see if all reference lib projects or src projects are added with correct path and name.


p
phreakhead

tl;dr: also check for stale SDK paths in the "local.properties" file.

Here's how I fixed it: I went through the answer given by Richard Le Mesurier, and also checked the path to the Android SDK in Window > Preferences > Android as mentioned by CommonsWare (since I did indeed change the SDK directory a while ago), however it still couldn't find it.

Then I noticed that I had a file called "local.properties" which referenced the old location for "sdk.dir". I changed that to the new location to match what was in Window > Preferences > Android. Then deselected the build target in Project > Properties > Android, hit Apply, re-selected it, and hit OK and cleaned the project. That worked! Thanks all!


ticking in one of the boxes in <project> -> Properties -> Android -> Project Build Target did it. There was none selected. Strange. I've also copied android-support-v4.jar to a freshly-created <project's root>/libs folder - don't know if it has to do with anything because in itself it didn't help, but then the tick did.
c
cedricliang

i have also encoutered this and solve it by changing the android choice in project properties. My error is because the project can't find proper lib from the android SDK. Then fix the project using android fix tool in right click of project, clean it and then correct.


M
Marmoy

I had this problem come out of nowhere.

What worked for me was to right-click the project, select Android Tools, Add support Library..

It is the android.jar that is missing, and this restores it.


D
Daniel Riegel

Another possible explanation is that Eclipse has forgotten its Android plugin. This can happen if you switch workspaces, as happened in my case. I tried to re-import an existing Android project, and it couldn't find the basic java system libraries, since it was pointing to the standard android jars. Reinstalling the android plugin (Help->Eclipse Marketplace, then search for "Android" and pick "Android Development Tools for Eclipse") fixes it.


u
user2019773

I right clicked project and Closed it. Then reopened it. That fixed the problem.


M
MSquare

In my case, ADT needed update (in Eclipse menu Help/Check for Updates, or Help/Install New Software). Check your ADT!


f
ffonz

I tried several options mentioned here, but nothing worked. Then I rebooted my Ubuntu machine and started Eclipse again. Then everything was solved. Just reboot.


C
Community

java.lang.Object cannot be resolved in Eclipse

This problems started to appear recently for me after I upgraded ADT. As suggested above, when I uncheck+Apply/check+Apply project build target it would help , but the problem would come back eventually. So instead I just added android.jar explicitly to the build. This is the entry in the .classpath file

    <classpathentry kind="lib" path="/Applications/adt-bundle-mac-x86_64/sdk/platforms/android-19/android.jar"/>

This is more of a workaround as I would have to change it every time I change the SDK version, but at least no need to play with properties to get it to build when I restart Eclipse.


v
velazcod

Try cleaning your project, that might help.

On eclipse, click on the menu item above called "Project", then click on "Clean Build". On that screen, check the checkbox that says "Clean projects selected below", select the project(s) that's giving you problems, and click Ok.

It will rebuild your project and that usually helps with strange eclipse errors like this.


Update your ADT on eclipse, they just pushed a new version to deal with some bugs: twitter.com/#!/romainguy/status/12222143299330050
I actually fixed this problem as CommonsWare described. And now I upgraded to ADT 8.0.1 and got the same problems again, but his fix solved it again.
M
Max

In my case, my project.properties had android-8 listed as the target, which I didn't have installed.


h
hihell

my case was not created the right AVD

after AVD created, go to project Property and find Android, select the right SDK version and then go to JAVA Build Path, delete the library (Unable to get system library for project) and add android library.


A
Adly

The best way here as I tried before, is to create a new project and choose :

create a project from an existing source and choose the location of the android project that you want to import, then next, you will see the build target of android like : 2.3.3 or 2.1 ..

Just choose one of them then finish!

You are done! ..


H
Hauleth

Try to create new project like this then try it

https://i.stack.imgur.com/2pnMa.jpg


after that clean the project and then try to run it
J
Joan

Remove the folder libs in your project


n
n611x007

Had the same issue (red erros all over my java source files) Solution was simple:

step 1. In the manifest file raise the version to android:minSdkVersion="8" (I created a new empty project and looked in it's manifest file) (it was originally android:minSdkVersion="4" because i want to support older android versions.)

step 2. right click the project and select Build

step 3. just to be safe: On the menu: Project Clean and check my project

step 4: finally I changed back In the manifest file to android:minSdkVersion="4" and it had no errors.

Hope it works for you.


C
Christ

In my case, The JRE went missing (disapear from Eclipse option).

All I did to fix this is re-add the JRE under Windows -> Preferences -> Java -> Installed JREs.

mine was located at /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home


w
windnnw

The way that helped me.

Take the following file from the working project: workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/Working-project-name/.indexes Replace the broken project file: workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/Broken-project-name/.indexes