com.android.dx.dex.cf.CfOptions Java Examples

The following examples show how to use com.android.dx.dex.cf.CfOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Main.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Copies relevant arguments over into CfOptions and DexOptions instances.
 */
public void makeOptionsObjects() {
    cfOptions = new CfOptions();
    cfOptions.positionInfo = positionInfo;
    cfOptions.localInfo = localInfo;
    cfOptions.strictNameCheck = strictNameCheck;
    cfOptions.optimize = optimize;
    cfOptions.optimizeListFile = optimizeListFile;
    cfOptions.dontOptimizeListFile = dontOptimizeListFile;
    cfOptions.statistics = statistics;

    if (warnings) {
        cfOptions.warn = context.err;
    } else {
        cfOptions.warn = context.noop;
    }

    dexOptions = new DexOptions(context.err);
    dexOptions.minSdkVersion = minSdkVersion;
    dexOptions.forceJumbo = forceJumbo;
    dexOptions.allowAllInterfaceMethodInvokes = allowAllInterfaceMethodInvokes;
}
 
Example #2
Source File: Main.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Copies relevant arguments over into CfOptions and DexOptions instances.
 */
public void makeOptionsObjects() {
    cfOptions = new CfOptions();
    cfOptions.positionInfo = positionInfo;
    cfOptions.localInfo = localInfo;
    cfOptions.strictNameCheck = strictNameCheck;
    cfOptions.optimize = optimize;
    cfOptions.optimizeListFile = optimizeListFile;
    cfOptions.dontOptimizeListFile = dontOptimizeListFile;
    cfOptions.statistics = statistics;

    if (warnings) {
        cfOptions.warn = context.err;
    } else {
        cfOptions.warn = context.noop;
    }

    dexOptions = new DexOptions(context.err);
    dexOptions.minSdkVersion = minSdkVersion;
    dexOptions.forceJumbo = forceJumbo;
    dexOptions.allowAllInterfaceMethodInvokes = allowAllInterfaceMethodInvokes;
}
 
Example #3
Source File: Main.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Copies relevant arguments over into CfOptions and DexOptions instances.
 */
public void makeOptionsObjects() {
    cfOptions = new CfOptions();
    cfOptions.positionInfo = positionInfo;
    cfOptions.localInfo = localInfo;
    cfOptions.strictNameCheck = strictNameCheck;
    cfOptions.optimize = optimize;
    cfOptions.optimizeListFile = optimizeListFile;
    cfOptions.dontOptimizeListFile = dontOptimizeListFile;
    cfOptions.statistics = statistics;

    if (warnings) {
        cfOptions.warn = context.err;
    } else {
        cfOptions.warn = context.noop;
    }

    dexOptions = new DexOptions();
    dexOptions.minSdkVersion = minSdkVersion;
    dexOptions.forceJumbo = forceJumbo;
}
 
Example #4
Source File: BaseAndroidClassLoader.java    From rhino-android with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Class<?> defineClass(String name, byte[] data) {
    try {
        DexOptions dexOptions = new DexOptions();
        DexFile dexFile = new DexFile(dexOptions);
        DirectClassFile classFile = new DirectClassFile(data, name.replace('.', '/') + ".class", true);
        classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
        classFile.getMagic();
        DxContext context = new DxContext();
        dexFile.add(CfTranslator.translate(context, classFile, null, new CfOptions(), dexOptions, dexFile));
        Dex dex = new Dex(dexFile.toDex(null, false));
        Dex oldDex = getLastDex();
        if (oldDex != null) {
            dex = new DexMerger(new Dex[]{dex, oldDex}, CollisionPolicy.KEEP_FIRST, context).merge();
        }
        return loadClass(dex, name);
    } catch (IOException | ClassNotFoundException e) {
        throw new FatalLoadingException(e);
    }
}
 
Example #5
Source File: Main.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Copies relevant arguments over into CfOptions and
 * DexOptions instances.
 */
public void makeOptionsObjects(DxContext context) {
    cfOptions = new CfOptions();
    cfOptions.positionInfo = positionInfo;
    cfOptions.localInfo = localInfo;
    cfOptions.strictNameCheck = strictNameCheck;
    cfOptions.optimize = optimize;
    cfOptions.optimizeListFile = optimizeListFile;
    cfOptions.dontOptimizeListFile = dontOptimizeListFile;
    cfOptions.statistics = statistics;

    if (warnings) {
        cfOptions.warn = context.err;
    } else {
        cfOptions.warn = context.noop;
    }

    dexOptions = new DexOptions();
    dexOptions.forceJumbo = forceJumbo;
}
 
Example #6
Source File: MainActivity.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public DexFile generateDexFile(List<byte[]> classByteCodes){
    DxContext dxContext=new DxContext();
    DexOptions dexOptions=new DexOptions();
    CfOptions cfOptions=new CfOptions();
    DexFile dexFile=new DexFile(dexOptions);
    for (byte[] cls:classByteCodes){
        DirectClassFile directClassFile=new DirectClassFile(cls,"",false);
        directClassFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
        directClassFile.getMagic();
        dexFile.add(CfTranslator.translate(dxContext,directClassFile,cls,cfOptions,dexOptions,dexFile));
    }
    return dexFile;
}
 
Example #7
Source File: Dexing.java    From bazel with Apache License 2.0 5 votes vote down vote up
public CfOptions toCfOptions(DxContext context) {
  CfOptions result = new CfOptions();
  result.localInfo = this.localInfo;
  result.optimize = this.optimize;
  result.warn = printWarnings ? context.err : Dexing.nullout;
  // Use dx's defaults
  result.optimizeListFile = null;
  result.dontOptimizeListFile = null;
  result.positionInfo = positionInfo;
  result.strictNameCheck = true;
  result.statistics = false; // we're not supporting statistics anyways
  return result;
}
 
Example #8
Source File: DexFileAggregatorTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
private static DexFile convertClass(Class<?> clazz) throws IOException {
  String path = clazz.getName().replace('.', '/') + ".class";
  try (InputStream in =
      Thread.currentThread().getContextClassLoader().getResourceAsStream(path)) {
    return new DexConverter(new Dexing(new DxContext(), new DexOptions(), new CfOptions()))
        .toDexFile(ByteStreams.toByteArray(in), path);
  }
}
 
Example #9
Source File: DexConversionEnqueuerTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
private void makeStuffer() {
  stuffer =
      new DexConversionEnqueuer(
          zip,
          newDirectExecutorService(),
          new DexConverter(new Dexing(new DxContext(), new DexOptions(), new CfOptions())),
          cache);
}
 
Example #10
Source File: DexLimitTrackerTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
private static DexFile convertClass(Class<?> clazz) throws IOException {
  String path = clazz.getName().replace('.', '/') + ".class";
  try (InputStream in =
      Thread.currentThread().getContextClassLoader().getResourceAsStream(path)) {
    return new DexConverter(new Dexing(new DxContext(), new DexOptions(), new CfOptions()))
        .toDexFile(ByteStreams.toByteArray(in), path);
  }
}
 
Example #11
Source File: AndroidClassLoadingStrategy.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ClassDefItem translate(DirectClassFile directClassFile,
                              byte[] binaryRepresentation,
                              CfOptions dexCompilerOptions,
                              DexOptions dexFileOptions,
                              DexFile dexFile) {
    throw new IllegalStateException("Could not resolve dispatcher: " + message);
}
 
Example #12
Source File: Dexing.java    From bazel with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
Dexing(DxContext context, DexOptions dexOptions, CfOptions cfOptions) {
  this.context = context;
  this.dexOptions = dexOptions;
  this.cfOptions = cfOptions;
}
 
Example #13
Source File: AndroidClassLoadingStrategy.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a default dex processor that ensures API version compatibility.
 *
 * @return A dex processor using an SDK compiler that ensures compatibility.
 */
protected static DexProcessor makeDefault() {
    DexOptions dexOptions = new DexOptions();
    DISPATCHER.setTargetApi(dexOptions, DEX_COMPATIBLE_API_VERSION);
    return new ForSdkCompiler(dexOptions, new CfOptions());
}
 
Example #14
Source File: AndroidClassLoadingStrategyTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
public Conversion create() {
    return new AndroidClassLoadingStrategy.DexProcessor.ForSdkCompiler(new DexOptions(), new CfOptions()).create();
}
 
Example #15
Source File: AndroidClassLoadingStrategy.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new Android SDK dex compiler-based dex processor.
 *
 * @param dexFileOptions     The dex file options to apply.
 * @param dexCompilerOptions The dex compiler options to apply.
 */
public ForSdkCompiler(DexOptions dexFileOptions, CfOptions dexCompilerOptions) {
    this.dexFileOptions = dexFileOptions;
    this.dexCompilerOptions = dexCompilerOptions;
}
 
Example #16
Source File: AndroidClassLoadingStrategy.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new class file definition.
 *
 * @param directClassFile      The direct class file to translate.
 * @param binaryRepresentation The file's binary representation.
 * @param dexCompilerOptions   The dex compiler options.
 * @param dexFileOptions       The dex file options.
 * @param dexFile              The dex file.
 * @return The translated class file definition.
 */
ClassDefItem translate(DirectClassFile directClassFile,
                       byte[] binaryRepresentation,
                       CfOptions dexCompilerOptions,
                       DexOptions dexFileOptions,
                       DexFile dexFile);