Search in sources :

Example 1 with DexOptions

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

the class DexMaker method getDexFile.

DexFile getDexFile() {
    if (outputDex == null) {
        DexOptions options = new DexOptions();
        options.targetApiLevel = 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 2 with DexOptions

use of com.android.dx.dex.DexOptions in project HL4A by HL4A.

the class 基本加载器 method defineClass.

public Class<?> defineClass(String name, byte[] data) {
    try {
        DexOptions dexOptions = new DexOptions();
        com.android.dx.dex.file.DexFile dexFile = new com.android.dx.dex.file.DexFile(dexOptions);
        DirectClassFile classFile = new DirectClassFile(data, name.replace('.', '/') + ".class", true);
        classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
        classFile.getMagic();
        dexFile.add(CfTranslator.translate(classFile, null, new CfOptions(), dexOptions, dexFile));
        Dex dex = new Dex(dexFile.toDex(null, false));
        if (oldDex != null) {
            dex = new DexMerger(dex, oldDex, CollisionPolicy.KEEP_FIRST).merge();
        }
        return loadClass(dex, name);
    } catch (IOException | ClassNotFoundException e) {
        throw new FatalLoadingException(e);
    }
}
Also used : DexMerger(com.android.dx.merge.DexMerger) DexOptions(com.android.dx.dex.DexOptions) IOException(java.io.IOException) DirectClassFile(com.android.dx.cf.direct.DirectClassFile) Dex(com.android.dex.Dex) CfOptions(com.android.dx.dex.cf.CfOptions)

Example 3 with DexOptions

use of com.android.dx.dex.DexOptions in project byte-buddy by raphw.

the class AndroidClassLoadingStrategyTest method testObjectProperties.

@Test
public void testObjectProperties() throws Exception {
    ObjectPropertyAssertion.of(AndroidClassLoadingStrategy.DexProcessor.ForSdkCompiler.class).apply();
    ObjectPropertyAssertion.of(AndroidClassLoadingStrategy.DexProcessor.ForSdkCompiler.Conversion.class).create(new ObjectPropertyAssertion.Creator<DexFile>() {

        @Override
        public DexFile create() {
            return new DexFile(new DexOptions());
        }
    }).apply();
}
Also used : DexOptions(com.android.dx.dex.DexOptions) DexFile(com.android.dx.dex.file.DexFile) Test(org.junit.Test)

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

Example 5 with DexOptions

use of com.android.dx.dex.DexOptions in project HL4A by HL4A.

the class DEX method 单个.

public static void 单个(String $文件, String $类名, String $输出) throws IOException {
    byte[] $字节 = 字节.读取($文件);
    DexOptions dexOptions = new DexOptions();
    com.android.dx.dex.file.DexFile dexFile = new com.android.dx.dex.file.DexFile(dexOptions);
    DirectClassFile classFile = new DirectClassFile($字节, $类名.replace('.', '/') + ".class", true);
    classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
    classFile.getMagic();
    dexFile.add(CfTranslator.translate(classFile, null, new CfOptions(), dexOptions, dexFile));
    Dex dex = new Dex(dexFile.toDex(null, false));
    dex.writeTo(文件.取文件对象($输出));
}
Also used : DirectClassFile(com.android.dx.cf.direct.DirectClassFile) Dex(com.android.dex.Dex) DexOptions(com.android.dx.dex.DexOptions) CfOptions(com.android.dx.dex.cf.CfOptions)

Aggregations

DexOptions (com.android.dx.dex.DexOptions)6 DirectClassFile (com.android.dx.cf.direct.DirectClassFile)3 CfOptions (com.android.dx.dex.cf.CfOptions)3 DexFile (com.android.dx.dex.file.DexFile)3 Dex (com.android.dex.Dex)2 IOException (java.io.IOException)2 StdAttributeFactory (com.android.dx.cf.direct.StdAttributeFactory)1 ParseException (com.android.dx.cf.iface.ParseException)1 DxContext (com.android.dx.command.dexer.DxContext)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 ZipException (java.util.zip.ZipException)1 Test (org.junit.Test)1 ClassReader (org.objectweb.asm.ClassReader)1 ClassWriter (org.objectweb.asm.ClassWriter)1