Don't require a dalvikvm to build.

Change-Id: I362820131580dfd1c6fc1eb45d0264723730f865
http://code.google.com/p/android/issues/detail?id=6322
diff --git a/dx/src/com/android/dx/gen/DexGenerator.java b/dx/src/com/android/dx/gen/DexGenerator.java
index 50f7718..8a9f5a3 100644
--- a/dx/src/com/android/dx/gen/DexGenerator.java
+++ b/dx/src/com/android/dx/gen/DexGenerator.java
@@ -30,10 +30,10 @@
 import com.android.dx.rop.cst.CstString;
 import com.android.dx.rop.cst.CstType;
 import com.android.dx.rop.cst.TypedConstant;
-import dalvik.system.PathClassLoader;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
 import java.util.jar.JarEntry;
 import java.util.jar.JarOutputStream;
 
@@ -104,14 +104,26 @@
          * TODO: load the dex from memory where supported.
          */
         File result = File.createTempFile("Generated", ".jar");
-//        result.deleteOnExit(); // TODO
+        result.deleteOnExit();
         JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(result));
         jarOut.putNextEntry(new JarEntry(DexFormat.DEX_IN_JAR_NAME));
         jarOut.write(dex);
         jarOut.closeEntry();
         jarOut.close();
-        System.out.println(result);
-
-        return new PathClassLoader(result.getPath(), parent);
+        try {
+            Class<?> pathClassLoader = Class.forName("dalvik.system.PathClassLoader");
+            return (ClassLoader) pathClassLoader.getConstructor(String.class, ClassLoader.class)
+                    .newInstance(result.getPath(), parent);
+        } catch (ClassNotFoundException e) {
+            throw new UnsupportedOperationException("load() requires a Dalvik VM", e);
+        } catch (InvocationTargetException e) {
+            throw new RuntimeException(e.getCause());
+        } catch (InstantiationException e) {
+            throw new AssertionError();
+        } catch (NoSuchMethodException e) {
+            throw new AssertionError();
+        } catch (IllegalAccessException e) {
+            throw new AssertionError();
+        }
     }
 }