Search in sources :

Example 1 with FastMultiDexer

use of com.taobao.android.builder.tools.multidex.FastMultiDexer in project atlas by alibaba.

the class DexByteCodeConverterHook method generateMainDexList.

private void generateMainDexList(File mainDexListFile) {
    Collection<File> inputs = AtlasBuildContext.atlasMainDexHelperMap.get(variantContext.getVariantName()).getAllMainDexJars();
    inputs.addAll(AtlasBuildContext.atlasMainDexHelperMap.get(variantContext.getVariantName()).getInputDirs());
    FastMultiDexer fastMultiDexer = (FastMultiDexer) AtlasBuildContext.androidBuilderMap.get(variantContext.getScope().getGlobalScope().getProject()).multiDexer;
    if (fastMultiDexer == null) {
        fastMultiDexer = new FastMultiDexer((AppVariantContext) variantContext);
    }
    Collection<File> files = null;
    try {
        files = fastMultiDexer.repackageJarList(inputs, mainDexListFile, variantContext.getScope().getVariantData().getName().toLowerCase().endsWith("release"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (files != null && files.size() > 0) {
        AtlasBuildContext.atlasMainDexHelperMap.get(variantContext.getVariantName()).addAllMainDexJars(files);
    }
}
Also used : FastMultiDexer(com.taobao.android.builder.tools.multidex.FastMultiDexer) JarFile(java.util.jar.JarFile) AppVariantContext(com.android.build.gradle.internal.api.AppVariantContext)

Example 2 with FastMultiDexer

use of com.taobao.android.builder.tools.multidex.FastMultiDexer in project atlas by alibaba.

the class AtlasMultiDexListTransform method transform.

public void transform(@NonNull TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException {
    if (mainDexListFile.exists() && !variantScope.getVariantData().getName().toLowerCase().endsWith("release")) {
        return;
    }
    LoggingManager loggingManager = transformInvocation.getContext().getLogging();
    loggingManager.captureStandardOutput(LogLevel.INFO);
    loggingManager.captureStandardError(LogLevel.WARN);
    Collection<File> inputs = AtlasBuildContext.atlasMainDexHelperMap.get(variantScope.getFullVariantName()).getAllMainDexJars();
    inputs.addAll(AtlasBuildContext.atlasMainDexHelperMap.get(variantScope.getFullVariantName()).getInputDirs());
    if (AtlasBuildContext.androidBuilderMap.get(variantScope.getGlobalScope().getProject()) == null) {
        super.transform(transformInvocation);
    } else if (AtlasBuildContext.androidBuilderMap.get(variantScope.getGlobalScope().getProject()).multiDexer == null) {
        super.transform(transformInvocation);
    }
    FastMultiDexer fastMultiDexer = (FastMultiDexer) AtlasBuildContext.androidBuilderMap.get(variantScope.getGlobalScope().getProject()).multiDexer;
    Collection<File> files = fastMultiDexer.repackageJarList(inputs, mainDexListFile, variantScope.getVariantData().getName().toLowerCase().endsWith("release"));
    if (files != null && files.size() > 0) {
        AtlasBuildContext.atlasMainDexHelperMap.get(variantScope.getFullVariantName()).addAllMainDexJars(files);
    }
}
Also used : FastMultiDexer(com.taobao.android.builder.tools.multidex.FastMultiDexer) LoggingManager(org.gradle.api.logging.LoggingManager) File(java.io.File)

Example 3 with FastMultiDexer

use of com.taobao.android.builder.tools.multidex.FastMultiDexer in project atlas by alibaba.

the class TransformReplacer method replaceMultiDexListTransform.

public void replaceMultiDexListTransform() {
    List<TransformTask> list = null;
    FastMultiDexer fastMultiDexer = new FastMultiDexer(variantContext);
    if (usingIncrementalDexing(variantContext.getScope())) {
        list = TransformManager.findTransformTaskByTransformType(variantContext, MainDexListTransform.class);
    } else {
        list = TransformManager.findTransformTaskByTransformType(variantContext, MultiDexTransform.class);
    }
    if (list.size() > 0 && fastMultiDexer.isFastMultiDexEnabled()) {
        com.android.build.gradle.internal.dsl.DexOptions dexOptions = variantContext.getScope().getGlobalScope().getExtension().getDexOptions();
        AtlasMultiDexListTransform atlasMultiDexListTransform = new AtlasMultiDexListTransform(variantContext.getScope(), dexOptions);
        for (TransformTask transformTask : list) {
            ReflectUtils.updateField(transformTask, "transform", atlasMultiDexListTransform);
            transformTask.doFirst(task -> AtlasBuildContext.androidBuilderMap.get(task.getProject()).multiDexer = (AtlasBuilder.MultiDexer) fastMultiDexer);
            transformTask.doLast(task -> AtlasBuildContext.androidBuilderMap.get(task.getProject()).multiDexer = null);
        }
    }
}
Also used : AtlasMultiDexListTransform(com.taobao.android.builder.tasks.transform.dex.AtlasMultiDexListTransform) FastMultiDexer(com.taobao.android.builder.tools.multidex.FastMultiDexer) FastMultiDexer(com.taobao.android.builder.tools.multidex.FastMultiDexer) TransformTask(com.android.build.gradle.internal.pipeline.TransformTask)

Example 4 with FastMultiDexer

use of com.taobao.android.builder.tools.multidex.FastMultiDexer in project atlas by alibaba.

the class TransformReplacer method generateMainDexList.

private void generateMainDexList(VariantScope variantScope) {
    File mainDexListFile = variantScope.getMainDexListFile();
    Collection<File> inputs = AtlasBuildContext.atlasMainDexHelperMap.get(variantScope.getFullVariantName()).getAllMainDexJars();
    inputs.addAll(AtlasBuildContext.atlasMainDexHelperMap.get(variantScope.getFullVariantName()).getInputDirs());
    FastMultiDexer fastMultiDexer = new FastMultiDexer(variantContext);
    Collection<File> files = null;
    try {
        files = fastMultiDexer.repackageJarList(inputs, mainDexListFile, variantScope.getVariantData().getName().toLowerCase().endsWith("release"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (files != null && files.size() > 0) {
        AtlasBuildContext.atlasMainDexHelperMap.get(variantScope.getFullVariantName()).addAllMainDexJars(files);
    }
}
Also used : FastMultiDexer(com.taobao.android.builder.tools.multidex.FastMultiDexer) IOException(java.io.IOException) File(java.io.File)

Aggregations

FastMultiDexer (com.taobao.android.builder.tools.multidex.FastMultiDexer)4 File (java.io.File)2 AppVariantContext (com.android.build.gradle.internal.api.AppVariantContext)1 TransformTask (com.android.build.gradle.internal.pipeline.TransformTask)1 AtlasMultiDexListTransform (com.taobao.android.builder.tasks.transform.dex.AtlasMultiDexListTransform)1 IOException (java.io.IOException)1 JarFile (java.util.jar.JarFile)1 LoggingManager (org.gradle.api.logging.LoggingManager)1