From 7695260241c862329e63ee2fa210af5ff3c95ea7 Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Mon, 18 Oct 2010 13:48:08 -0700 Subject: [PATCH] DexWrapper is now loaded by the SDK instead of the platforms. Since tools_r8, dx.jar is now located in platform-tools. instead of platforms/android-/tools/lib/. There is therefore no need for all the platforms to load their own dx.jar through reflection into DexWrapper. The SDK now does it for all, and the builders query the SDK for the wrapper. Change-Id: Ia79ccaf95237f2b25b43f26241e6335acc7050a3 --- .../eclipse/adt/internal/build/BuildHelper.java | 11 ++------- .../adt/internal/sdk/AndroidTargetData.java | 11 --------- .../adt/internal/sdk/AndroidTargetParser.java | 16 +------------ .../android/ide/eclipse/adt/internal/sdk/Sdk.java | 27 ++++++++++++++++++++-- .../src/com/android/sdklib/IAndroidTarget.java | 8 +++++-- 5 files changed, 34 insertions(+), 39 deletions(-) diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java index 6462e0325..2fde10192 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java @@ -23,7 +23,6 @@ import com.android.ide.eclipse.adt.internal.preferences.AdtPrefs; import com.android.ide.eclipse.adt.internal.preferences.AdtPrefs.BuildVerbosity; import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper; import com.android.ide.eclipse.adt.internal.project.ProjectHelper; -import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData; import com.android.ide.eclipse.adt.internal.sdk.Sdk; import com.android.prefs.AndroidLocation.AndroidLocationException; import com.android.sdklib.IAndroidTarget; @@ -495,15 +494,9 @@ public class BuildHelper { public void executeDx(IJavaProject javaProject, String[] inputPaths, String osOutFilePath) throws CoreException, DexException { - IAndroidTarget target = Sdk.getCurrent().getTarget(mProject); - AndroidTargetData targetData = Sdk.getCurrent().getTargetData(target); - if (targetData == null) { - throw new CoreException(new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, - Messages.ApkBuilder_UnableBuild_Dex_Not_loaded)); - } - // get the dex wrapper - DexWrapper wrapper = targetData.getDexWrapper(); + Sdk sdk = Sdk.getCurrent(); + DexWrapper wrapper = sdk.getDexWrapper(); if (wrapper == null) { throw new CoreException(new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/AndroidTargetData.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/AndroidTargetData.java index 765dfbb8d..c3885450a 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/AndroidTargetData.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/AndroidTargetData.java @@ -17,7 +17,6 @@ package com.android.ide.eclipse.adt.internal.sdk; import com.android.ide.eclipse.adt.AdtPlugin; -import com.android.ide.eclipse.adt.internal.build.DexWrapper; import com.android.ide.eclipse.adt.internal.editors.descriptors.IDescriptorProvider; import com.android.ide.eclipse.adt.internal.editors.layout.descriptors.LayoutDescriptors; import com.android.ide.eclipse.adt.internal.editors.manifest.descriptors.AndroidManifestDescriptors; @@ -83,8 +82,6 @@ public class AndroidTargetData { private final IAndroidTarget mTarget; - private DexWrapper mDexWrapper; - /** * mAttributeValues is a map { key => list [ values ] }. * The key for the map is "(element-xml-name,attribute-namespace:attribute-xml-local-name)". @@ -115,10 +112,6 @@ public class AndroidTargetData { mTarget = androidTarget; } - void setDexWrapper(DexWrapper wrapper) { - mDexWrapper = wrapper; - } - /** * Creates an AndroidTargetData object. * @param platformLibraries @@ -155,10 +148,6 @@ public class AndroidTargetData { setOptionalLibraries(platformLibraries, optionalLibraries); } - public DexWrapper getDexWrapper() { - return mDexWrapper; - } - public IResourceRepository getSystemResources() { return mSystemResourceRepository; } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/AndroidTargetParser.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/AndroidTargetParser.java index fb19fc8bb..9c273fb8f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/AndroidTargetParser.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/AndroidTargetParser.java @@ -18,7 +18,6 @@ package com.android.ide.eclipse.adt.internal.sdk; import com.android.ide.eclipse.adt.AdtPlugin; import com.android.ide.eclipse.adt.AndroidConstants; -import com.android.ide.eclipse.adt.internal.build.DexWrapper; import com.android.ide.eclipse.adt.internal.editors.layout.descriptors.LayoutDescriptors; import com.android.ide.eclipse.adt.internal.editors.manifest.descriptors.AndroidManifestDescriptors; import com.android.ide.eclipse.adt.internal.editors.menu.descriptors.MenuDescriptors; @@ -94,23 +93,10 @@ public final class AndroidTargetParser { try { SubMonitor progress = SubMonitor.convert(monitor, String.format("Parsing SDK %1$s", mAndroidTarget.getName()), - 14); + 13); AndroidTargetData targetData = new AndroidTargetData(mAndroidTarget); - // load DX. - DexWrapper dexWrapper = new DexWrapper(); - IStatus res = dexWrapper.loadDex(mAndroidTarget.getPath(IAndroidTarget.DX_JAR)); - if (res != Status.OK_STATUS) { - return new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, - String.format("dx.jar loading failed for target '%1$s'", - mAndroidTarget.getFullName())); - } - - // we have loaded dx. - targetData.setDexWrapper(dexWrapper); - progress.worked(1); - // parse the rest of the data. AndroidJarLoader classLoader = 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 61d35c299..d2f00da2b 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 @@ -19,6 +19,7 @@ package com.android.ide.eclipse.adt.internal.sdk; import com.android.ddmlib.IDevice; import com.android.ide.eclipse.adt.AdtPlugin; import com.android.ide.eclipse.adt.AndroidConstants; +import com.android.ide.eclipse.adt.internal.build.DexWrapper; import com.android.ide.eclipse.adt.internal.project.AndroidClasspathContainerInitializer; import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper; import com.android.ide.eclipse.adt.internal.project.ProjectHelper; @@ -113,6 +114,7 @@ public final class Sdk { } private final SdkManager mManager; + private final DexWrapper mDexWrapper; private final AvdManager mAvdManager; /** Map associating an {@link IAndroidTarget} to an {@link AndroidTargetData} */ @@ -228,13 +230,25 @@ public final class Sdk { // get an SdkManager object for the location SdkManager manager = SdkManager.createManager(sdkLocation, log); if (manager != null) { + // load DX. + DexWrapper dexWrapper = new DexWrapper(); + String dexLocation = + sdkLocation + File.separator + + SdkConstants.OS_SDK_PLATFORM_TOOLS_LIB_FOLDER + SdkConstants.FN_DX_JAR; + IStatus res = dexWrapper.loadDex(dexLocation); + if (res != Status.OK_STATUS) { + log.error(null, res.getMessage()); + dexWrapper = null; + } + + // create the AVD Manager AvdManager avdManager = null; try { avdManager = new AvdManager(manager, log); } catch (AndroidLocationException e) { log.error(e, "Error parsing the AVDs"); } - sCurrentSdk = new Sdk(manager, avdManager); + sCurrentSdk = new Sdk(manager, dexWrapper, avdManager); return sCurrentSdk; } else { StringBuilder sb = new StringBuilder("Error Loading the SDK:\n"); @@ -538,6 +552,14 @@ public final class Sdk { } /** + * Returns a {@link DexWrapper} object to be used to execute dx commands. If dx.jar was not + * loaded properly, then this will return null. + */ + public DexWrapper getDexWrapper() { + return mDexWrapper; + } + + /** * Returns the {@link AvdManager}. If the AvdManager failed to parse the AVD folder, this could * be null. */ @@ -599,8 +621,9 @@ public final class Sdk { } } - private Sdk(SdkManager manager, AvdManager avdManager) { + private Sdk(SdkManager manager, DexWrapper dexWrapper, AvdManager avdManager) { mManager = manager; + mDexWrapper = dexWrapper; mAvdManager = avdManager; // listen to projects closing diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/IAndroidTarget.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/IAndroidTarget.java index 1016ba8cb..dc75c61dc 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/IAndroidTarget.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/IAndroidTarget.java @@ -67,9 +67,13 @@ public interface IAndroidTarget extends Comparable { public final static int AAPT = 20; /** OS Path to the target's version of the aidl tool. */ public final static int AIDL = 21; - /** OS Path to the target's version of the dx too. */ + /** OS Path to the target's version of the dx too.
+ * This is deprecated as dx is now in the platform tools and not in the platform. */ + @Deprecated public final static int DX = 22; - /** OS Path to the target's version of the dx.jar file. */ + /** OS Path to the target's version of the dx.jar file.
+ * This is deprecated as dx.jar is now in the platform tools and not in the platform.. */ + @Deprecated public final static int DX_JAR = 23; /** OS Path to the "ant" folder which contains the ant build rules (ver 2 and above) */ public final static int ANT = 24; -- 2.11.0