A co-worker gave me a second package for an Android app I'm working on and there are a couple of "java.awt" and "javax.swing" imports in the classes, which were all marked with red "x".
Eclipse (Mars.2, 4.5.2) already knows what Java versions are installed (Window - Preferences - Java - Installed JREs, "jdk1.8.0_161" has a checkmark next to it) and I just checked if the JAVA_HOME environment variable is still there (which it is). To fix the problem, I still had to add a JRE system library (1.8.0 v161) to the project's build path.
The actual problem is: Every time I restart Eclipse, the red "x" are back and I have to add Java again.
How can I keep Eclipse from forgetting the library?
Edit: The classpath for my project says:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry 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="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
Neither java.awt
nor javax.swing
are part of the Android API (because Android uses its own UI toolkit). You can add a JRE/JDK's lib/rt.jar
via Add External JARs... to your Java Build Path, but that's a dirty trick.