summaryrefslogtreecommitdiffstats
path: root/dx
diff options
context:
space:
mode:
authorJesse Wilson <jessewilson@google.com>2011-04-15 10:34:33 -0700
committerJesse Wilson <jessewilson@google.com>2011-04-15 10:34:33 -0700
commitb665fb24d785e27480cc9b8debcf9edf4ac65d2c (patch)
tree25e35b1c2f72e3b1696eca36a98400c70f307f8a /dx
parent376e9e5a71761ed687ce107f72f42b2ba93825f1 (diff)
downloadandroid_dalvik-b665fb24d785e27480cc9b8debcf9edf4ac65d2c.tar.gz
android_dalvik-b665fb24d785e27480cc9b8debcf9edf4ac65d2c.tar.bz2
android_dalvik-b665fb24d785e27480cc9b8debcf9edf4ac65d2c.zip
Don't require a dalvikvm to build.
Change-Id: I362820131580dfd1c6fc1eb45d0264723730f865 http://code.google.com/p/android/issues/detail?id=6322
Diffstat (limited to 'dx')
-rw-r--r--dx/src/com/android/dx/gen/DexGenerator.java22
1 files changed, 17 insertions, 5 deletions
diff --git a/dx/src/com/android/dx/gen/DexGenerator.java b/dx/src/com/android/dx/gen/DexGenerator.java
index 50f7718b8..8a9f5a314 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.CstShort;
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 @@ public final class DexGenerator {
* 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();
+ }
}
}