aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/LibraryClasspathContainerInitializer.java36
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java12
2 files changed, 43 insertions, 5 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/LibraryClasspathContainerInitializer.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/LibraryClasspathContainerInitializer.java
index 3d0d988..6d0ed5a 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/LibraryClasspathContainerInitializer.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/LibraryClasspathContainerInitializer.java
@@ -91,6 +91,42 @@ public class LibraryClasspathContainerInitializer extends ClasspathContainerInit
return null;
}
+ try {
+ // First check that the project has a library-type container.
+ IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
+ IClasspathEntry[] oldRawClasspath = rawClasspath;
+
+ boolean foundLibrariesContainer = false;
+ for (IClasspathEntry entry : rawClasspath) {
+ // get the entry and kind
+ int kind = entry.getEntryKind();
+
+ if (kind == IClasspathEntry.CPE_CONTAINER) {
+ String path = entry.getPath().toString();
+ if (AdtConstants.CONTAINER_LIBRARIES.equals(path)) {
+ foundLibrariesContainer = true;
+ break;
+ }
+ }
+ }
+
+ // same thing for the library container
+ if (foundLibrariesContainer == false) {
+ // add the android container to the array
+ rawClasspath = ProjectHelper.addEntryToClasspath(rawClasspath,
+ JavaCore.newContainerEntry(new Path(AdtConstants.CONTAINER_LIBRARIES)));
+ }
+
+ // set the new list of entries to the project
+ if (rawClasspath != oldRawClasspath) {
+ javaProject.setRawClasspath(rawClasspath, new NullProgressMonitor());
+ }
+ } catch (JavaModelException e) {
+ // This really shouldn't happen, but if it does, simply return null (the calling
+ // method will fails as well)
+ return null;
+ }
+
// check if the project has a valid target.
ProjectState state = Sdk.getProjectState(iProject);
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java
index 550f53f..ba8ce1a 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java
@@ -40,8 +40,8 @@ import com.android.sdklib.SdkConstants;
import com.android.sdklib.SdkManager;
import com.android.sdklib.internal.avd.AvdManager;
import com.android.sdklib.internal.project.ProjectProperties;
-import com.android.sdklib.internal.project.ProjectProperties.PropertyType;
import com.android.sdklib.internal.project.ProjectPropertiesWorkingCopy;
+import com.android.sdklib.internal.project.ProjectProperties.PropertyType;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarkerDelta;
@@ -66,8 +66,8 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Set;
+import java.util.Map.Entry;
/**
* Central point to load, manipulate and deal with the Android SDK. Only one SDK can be used
@@ -440,9 +440,11 @@ public final class Sdk {
*/
public IAndroidTarget loadTarget(ProjectState state) {
IAndroidTarget target = null;
- String hash = state.getTargetHashString();
- if (hash != null) {
- state.setTarget(target = getTargetFromHashString(hash));
+ if (state != null) {
+ String hash = state.getTargetHashString();
+ if (hash != null) {
+ state.setTarget(target = getTargetFromHashString(hash));
+ }
}
return target;