Search in sources :

Example 6 with DexOptions

use of com.android.dx.dex.DexOptions in project dexmaker by linkedin.

the class DexMaker method generate.

/**
 * 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);
    }
}
Also used : DexOptions(com.android.dx.dex.DexOptions) IOException(java.io.IOException) DexFile(com.android.dx.dex.file.DexFile)

Example 7 with DexOptions

use of com.android.dx.dex.DexOptions in project UniverseCore by EB-wilson.

the class DexMaker method generate.

/**
 * 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);
    }
}
Also used : DexOptions(com.android.dx.dex.DexOptions) IOException(java.io.IOException) DexFile(com.android.dx.dex.file.DexFile)

Example 8 with DexOptions

use of com.android.dx.dex.DexOptions in project UniverseCore by EB-wilson.

the class DexMaker method getDexFile.

DexFile getDexFile() {
    if (outputDex == null) {
        DexOptions options = new DexOptions();
        options.minSdkVersion = DexFormat.API_NO_EXTENDED_OPCODES;
        outputDex = new DexFile(options);
    }
    return outputDex;
}
Also used : DexOptions(com.android.dx.dex.DexOptions) DexFile(com.android.dx.dex.file.DexFile)

Example 9 with DexOptions

use of com.android.dx.dex.DexOptions in project QTool by Hicores.

the class DiscreteFilesClassLoader method findClass.

/**
 */
public Class findClass(String name) throws ClassNotFoundException {
    // Load it if it's one of our classes
    ClassSource source = map.get(name);
    if (source != null) {
        byte[] code = source.getCode(name);
        try {
            DexOptions dexOptions = new DexOptions();
            DexFile dexFile = new DexFile(dexOptions);
            DxContext dxContext = new DxContext();
            DirectClassFile directClassFile = new DirectClassFile(code, String.format("%s.class", name.replace(".", "/")), true);
            directClassFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
            dexFile.add(CfTranslator.translate(dxContext, directClassFile, code, new CfOptions(), dexOptions, dexFile));
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            dexFile.writeTo(byteArrayOutputStream, null, true);
            byteArrayOutputStream.close();
            byte[] byteArray = byteArrayOutputStream.toByteArray();
            if (byteArray != null) {
                ClassLoader mLoader = new InMemoryDexClassLoader(ByteBuffer.wrap(byteArray), new FixClassloader(getClass().getClassLoader(), this.classManager));
                Class<?> loadClass = mLoader.loadClass(name);
                this.classManager.classMap.put(name, loadClass);
                return loadClass;
            }
            return defineClass(name, code, 0, code.length);
        } catch (Exception ioe) {
        }
        return defineClass(name, code, 0, code.length);
    } else
        // to find the class...
        return super.findClass(name);
}
Also used : DexOptions(com.android.dx.dex.DexOptions) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DexFile(com.android.dx.dex.file.DexFile) DxContext(com.android.dx.command.dexer.DxContext) DirectClassFile(com.android.dx.cf.direct.DirectClassFile) InMemoryDexClassLoader(dalvik.system.InMemoryDexClassLoader) InMemoryDexClassLoader(dalvik.system.InMemoryDexClassLoader) CfOptions(com.android.dx.dex.cf.CfOptions) ClassSource(bsh.classpath.BshClassPath.ClassSource)

Aggregations

DexOptions (com.android.dx.dex.DexOptions)9 DexFile (com.android.dx.dex.file.DexFile)6 DirectClassFile (com.android.dx.cf.direct.DirectClassFile)4 CfOptions (com.android.dx.dex.cf.CfOptions)4 IOException (java.io.IOException)3 Dex (com.android.dex.Dex)2 DxContext (com.android.dx.command.dexer.DxContext)2 ClassSource (bsh.classpath.BshClassPath.ClassSource)1 StdAttributeFactory (com.android.dx.cf.direct.StdAttributeFactory)1 ParseException (com.android.dx.cf.iface.ParseException)1 DexMerger (com.android.dx.merge.DexMerger)1 DexException (com.googlecode.d2j.DexException)1 ClassVisitorFactory (com.googlecode.d2j.dex.ClassVisitorFactory)1 Dex2Asm (com.googlecode.d2j.dex.Dex2Asm)1 LambadaNameSafeClassAdapter (com.googlecode.d2j.dex.LambadaNameSafeClassAdapter)1 DexMethodNode (com.googlecode.d2j.node.DexMethodNode)1 BaksmaliDumper (com.googlecode.d2j.smali.BaksmaliDumper)1 InMemoryDexClassLoader (dalvik.system.InMemoryDexClassLoader)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ZipException (java.util.zip.ZipException)1