/** * Generates a dex file and returns its bytes. */ public byte[] generate() { if (outputDex == null) { DexOptions options = new DexOptions(); options.minSdkVersion = DexFormat.API_NO_EXTENDED_OPCODES; outputDex = new DexFile(options); } for (TypeDeclaration typeDeclaration : types.values()) { outputDex.add(typeDeclaration.toClassDefItem()); } try { return outputDex.toDex(null, false); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Generates a dex file and returns its bytes. */ public byte[] generate() { DexOptions options = new DexOptions(); options.targetApiLevel = DexFormat.API_NO_EXTENDED_OPCODES; DexFile outputDex = new DexFile(options); for (TypeDeclaration typeDeclaration : types.values()) { outputDex.add(typeDeclaration.toClassDefItem()); } try { return outputDex.toDex(null, false); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Generates a dex file and returns its bytes. */ public byte[] generate() { if (outputDex == null) { DexOptions options = new DexOptions(); options.targetApiLevel = DexFormat.API_NO_EXTENDED_OPCODES; outputDex = new DexFile(options); } for (TypeDeclaration typeDeclaration : types.values()) { outputDex.add(typeDeclaration.toClassDefItem()); } try { return outputDex.toDex(null, false); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Returns a .dex formatted file. */ public byte[] generate() { DexFile outputDex = new DexFile(new DexOptions()); for (TypeDeclaration typeDeclaration : types.values()) { outputDex.add(typeDeclaration.toClassDefItem()); } try { return outputDex.toDex(null, false); } catch (IOException e) { throw new RuntimeException(e); } }
gcl.parseClass(scriptText); byte[] dalvikBytecode = new byte[0]; dalvikBytecode = dexFile.toDex(new OutputStreamWriter(new ByteArrayOutputStream()), false);
private static final byte[] dex(String className, byte[] classData) throws ClassFormatError { try { DexOptions dexOptions = new DexOptions(); DexFile dxFile = new DexFile(dexOptions); CfOptions cfOptions = new CfOptions(); dxFile.add(CfTranslator.translate(className.replace('.', '/') + ".class", classData, cfOptions, dexOptions)); StringWriter out = BridJ.debug ? new StringWriter() : null; byte[] dexData = dxFile.toDex(out, false); if (BridJ.debug) { BridJ.info("Dex output for class " + className + " : " + out); } return dexData; } catch (IOException ex) { throw new ClassFormatError("Unable to convert class data to Dalvik code using Dex : " + ex); } }
try byte[] rawDex= dexFile.toDex(null, false); OutputFile result= new OutputFile(rawDex); result.setLocation(classFile.getLocation());