Search in sources :

Example 11 with TransformTask

use of com.android.build.gradle.internal.pipeline.TransformTask in project atlas by alibaba.

the class AwbProguradHook method hookProguardTask.

/**
     * hook混淆的任务,加入awb的混淆配置
     *
     * @param appVariantContext
     */
public void hookProguardTask(final AppVariantContext appVariantContext) {
    final VariantScope variantScope = appVariantContext.getScope();
    List<TransformTask> proguaradTransformTasks = getTransformTaskByTransformType(appVariantContext, ProGuardTransform.class);
    for (TransformTask proguaradTransformTask : proguaradTransformTasks) {
        final ProGuardTransform proGuardTransform = (ProGuardTransform) proguaradTransformTask.getTransform();
        if (null != proGuardTransform) {
            proguaradTransformTask.doFirst(new Action<Task>() {

                @Override
                public void execute(Task task) {
                    GlobalScope globalScope = variantScope.getGlobalScope();
                    File proguardOut = new File(Joiner.on(File.separatorChar).join(String.valueOf(globalScope.getBuildDir()), FD_OUTPUTS, "mapping", variantScope.getVariantConfiguration().getDirName()));
                    //为了方便排查,先把configuration打印到目录
                    proGuardTransform.printconfiguration(new File(proguardOut, "tmp_config.cfg"));
                    final File outConfigFile = new File(proguardOut, "awb_config.cfg");
                    //增加awb的配置
                    AndroidDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(variantScope.getVariantConfiguration().getFullName());
                    if (null == dependencyTree) {
                        throw new StopExecutionException("DependencyTree cannot be null!");
                    }
                    if (dependencyTree.getAwbBundles().size() > 0) {
                        BaseVariantOutputData vod = appVariantContext.getVariantData().getOutputs().get(0);
                        AppVariantOutputContext appVariantOutputContext = getAppVariantOutputContext(appVariantContext, vod);
                        File awbObfuscatedDir = new File(globalScope.getIntermediatesDir(), "/classes-proguard/" + variantScope.getVariantConfiguration().getDirName());
                        AwbProguardConfiguration awbProguardConfiguration = new AwbProguardConfiguration(appVariantOutputContext.getAwbTransformMap().values(), awbObfuscatedDir, appVariantOutputContext);
                        try {
                            awbProguardConfiguration.printConfigFile(outConfigFile);
                        } catch (IOException e) {
                            throw new GradleException("", e);
                        }
                        proGuardTransform.setConfigurationFiles(new Supplier<Collection<File>>() {

                            @Override
                            public Collection<File> get() {
                                Set<File> proguardFiles = new HashSet<File>();
                                ((HashSet<File>) proguardFiles).add(outConfigFile);
                                return proguardFiles;
                            }
                        });
                    }
                    File mappingFile = null;
                    if (null != appVariantContext.apContext.getApExploredFolder() && appVariantContext.apContext.getApExploredFolder().exists()) {
                        mappingFile = new File(appVariantContext.apContext.getApExploredFolder(), "mapping.txt");
                    } else {
                        mappingFile = new File(appVariantContext.getScope().getGlobalScope().getProject().getProjectDir(), "mapping.txt");
                    }
                    if (null != mappingFile && mappingFile.exists()) {
                        proGuardTransform.applyTestedMapping(mappingFile);
                    }
                }
            });
        }
    }
}
Also used : GlobalScope(com.android.build.gradle.internal.scope.GlobalScope) VariantScope(com.android.build.gradle.internal.scope.VariantScope) TransformTask(com.android.build.gradle.internal.pipeline.TransformTask) Task(org.gradle.api.Task) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) BaseVariantOutputData(com.android.build.gradle.internal.variant.BaseVariantOutputData) AppVariantOutputContext(com.android.build.gradle.internal.api.AppVariantOutputContext) IOException(java.io.IOException) ProGuardTransform(com.android.build.gradle.internal.transforms.ProGuardTransform) StopExecutionException(org.gradle.api.tasks.StopExecutionException) AwbProguardConfiguration(com.taobao.android.builder.tasks.app.bundle.AwbProguardConfiguration) GradleException(org.gradle.api.GradleException) TransformTask(com.android.build.gradle.internal.pipeline.TransformTask) Supplier(java.util.function.Supplier) File(java.io.File)

Example 12 with TransformTask

use of com.android.build.gradle.internal.pipeline.TransformTask in project atlas by alibaba.

the class TransformReplacer method repalaceSomeInstantTransform.

public void repalaceSomeInstantTransform(BaseVariantOutput vod) {
    variantContext.getProject().getTasks().withType(FastDeployRuntimeExtractorTask.class).forEach(fastDeployRuntimeExtractorTask -> fastDeployRuntimeExtractorTask.setEnabled(false));
    List<TransformTask> baseTransforms = TransformManager.findTransformTaskByTransformType(variantContext, InstantRunDependenciesApkBuilder.class);
    if (baseTransforms != null && baseTransforms.size() > 0) {
        for (TransformTask transformTask : baseTransforms) {
            transformTask.setEnabled(false);
        }
    }
    List<TransformTask> transforms = TransformManager.findTransformTaskByTransformType(variantContext, InstantRunTransform.class);
    if (transforms != null && transforms.size() > 0) {
        for (TransformTask transformTask : transforms) {
            TaobaoInstantRunTransform taobaoInstantRunTransform = new TaobaoInstantRunTransform(variantContext, variantContext.getAppVariantOutputContext(ApkDataUtils.get(vod)), WaitableExecutor.useGlobalSharedThreadPool(), variantContext.getScope());
            ReflectUtils.updateField(transformTask, "transform", taobaoInstantRunTransform);
        }
    }
    List<TransformTask> verifytransforms = TransformManager.findTransformTaskByTransformType(variantContext, InstantRunVerifierTransform.class);
    if (verifytransforms != null && verifytransforms.size() > 0) {
        for (TransformTask transformTask : verifytransforms) {
            transformTask.setEnabled(false);
        }
    }
    List<TransformTask> transforms1 = TransformManager.findTransformTaskByTransformType(variantContext, ExtractJarsTransform.class);
    if (transforms1 != null && transforms1.size() > 0) {
        for (TransformTask transformTask : transforms1) {
            TaobaoExtractJarsTransform taobaoExtractJarsTransform = new TaobaoExtractJarsTransform(variantContext, variantContext.getAppVariantOutputContext(ApkDataUtils.get(vod)), ImmutableSet.of(QualifiedContent.DefaultContentType.CLASSES), ImmutableSet.of(QualifiedContent.Scope.SUB_PROJECTS));
            ReflectUtils.updateField(transformTask, "transform", taobaoExtractJarsTransform);
        }
    }
    List<TransformTask> transforms2 = TransformManager.findTransformTaskByTransformType(variantContext, InstantRunDex.class);
    if (transforms2 != null && transforms2.size() > 0) {
        for (TransformTask transformTask : transforms2) {
            TaobaoInstantRunDex taobaoInstantRunDex = new TaobaoInstantRunDex(variantContext, variantContext.getScope(), variantContext.getScope().getGlobalScope().getAndroidBuilder().getDexByteCodeConverter(), (DexOptions) ReflectUtils.getField(transformTask.getTransform(), "dexOptions"), variantContext.getProject().getLogger(), (Integer) ReflectUtils.getField(transformTask.getTransform(), "minSdkForDx"), vod);
            ReflectUtils.updateField(transformTask, "transform", taobaoInstantRunDex);
        }
    }
    List<TransformTask> transformTaskList = TransformManager.findTransformTaskByTransformType(variantContext, InstantRunSliceSplitApkBuilder.class);
    if (transformTaskList != null && transformTaskList.size() > 0) {
        for (TransformTask transformTask : transformTaskList) {
            transformTask.setEnabled(false);
        }
    }
    List<TransformTask> transformTaskList1 = TransformManager.findTransformTaskByTransformType(variantContext, InstantRunSlicer.class);
    if (transformTaskList1 != null && transformTaskList1.size() > 0) {
        for (TransformTask transformTask : transformTaskList1) {
            transformTask.setEnabled(false);
        // TaobaoInstantRunSlicer taobaoInstantRunSlicer = new TaobaoInstantRunSlicer(variantContext.getProject().getLogger(),variantContext.getScope());
        // ReflectUtils.updateField(transformTask,"transform",taobaoInstantRunSlicer);
        }
    }
}
Also used : FastDeployRuntimeExtractorTask(com.android.build.gradle.tasks.ir.FastDeployRuntimeExtractorTask) TransformTask(com.android.build.gradle.internal.pipeline.TransformTask)

Example 13 with TransformTask

use of com.android.build.gradle.internal.pipeline.TransformTask in project atlas by alibaba.

the class TransformReplacer method replaceFixStackFramesTransform.

public void replaceFixStackFramesTransform(BaseVariantOutput vod) {
    List<TransformTask> baseTransforms = TransformManager.findTransformTaskByTransformType(variantContext, FixStackFramesTransform.class);
    for (TransformTask transformTask : baseTransforms) {
        FixStackFramesTransform transform = (FixStackFramesTransform) transformTask.getTransform();
        AtlasFixStackFramesTransform atlasFixStackFramesTransform = new AtlasFixStackFramesTransform(variantContext.getAppVariantOutputContext(ApkDataUtils.get(vod)), (Supplier<List<File>>) ReflectUtils.getField(transform, "androidJarClasspath"), (List<Path>) ReflectUtils.getField(transform, "compilationBootclasspath"), (FileCache) ReflectUtils.getField(transform, "userCache"));
        atlasFixStackFramesTransform.oldTransform = transform;
        ReflectUtils.updateField(transformTask, "transform", atlasFixStackFramesTransform);
    }
}
Also used : Path(java.nio.file.Path) TransformTask(com.android.build.gradle.internal.pipeline.TransformTask) List(java.util.List)

Example 14 with TransformTask

use of com.android.build.gradle.internal.pipeline.TransformTask 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 15 with TransformTask

use of com.android.build.gradle.internal.pipeline.TransformTask in project atlas by alibaba.

the class TransformReplacer method replaceMergeJavaResourcesTransform.

public void replaceMergeJavaResourcesTransform(AppVariantContext appVariantContext, BaseVariantOutput vod) {
    List<TransformTask> baseTransforms = TransformManager.findTransformTaskByTransformType(variantContext, MergeJavaResourcesTransform.class);
    for (TransformTask transformTask : baseTransforms) {
        MergeJavaResourcesTransform transform = (MergeJavaResourcesTransform) transformTask.getTransform();
        PackagingOptions packagingOptions = (PackagingOptions) ReflectUtils.getField(transform, "packagingOptions");
        packagingOptions.exclude("**.aidl");
        packagingOptions.exclude("**.cfg");
        Set<? super QualifiedContent.Scope> mergeScopes = (Set<? super QualifiedContent.Scope>) ReflectUtils.getField(transform, "mergeScopes");
        Set<QualifiedContent.ContentType> mergedType = (Set<QualifiedContent.ContentType>) ReflectUtils.getField(transform, "mergedType");
        String name = (String) ReflectUtils.getField(transform, "name");
        AtlasMergeJavaResourcesTransform atlasMergeJavaResourcesTransform = new AtlasMergeJavaResourcesTransform(appVariantContext.getAppVariantOutputContext(ApkDataUtils.get(vod)), packagingOptions, mergeScopes, mergedType.iterator().next(), name, appVariantContext.getScope());
        ReflectUtils.updateField(transformTask, "transform", atlasMergeJavaResourcesTransform);
    }
}
Also used : QualifiedContent(com.android.build.api.transform.QualifiedContent) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) PackagingScope(com.android.build.gradle.internal.scope.PackagingScope) DefaultGradlePackagingScope(com.android.build.gradle.internal.scope.DefaultGradlePackagingScope) VariantScope(com.android.build.gradle.internal.scope.VariantScope) PackageScope(groovy.transform.PackageScope) TransformTask(com.android.build.gradle.internal.pipeline.TransformTask) PackagingOptions(com.android.build.gradle.internal.dsl.PackagingOptions)

Aggregations

TransformTask (com.android.build.gradle.internal.pipeline.TransformTask)18 File (java.io.File)4 List (java.util.List)3 BaseVariantOutput (com.android.build.gradle.api.BaseVariantOutput)2 ExtraModelInfo (com.android.build.gradle.internal.ExtraModelInfo)2 GradleJavaProcessExecutor (com.android.build.gradle.internal.process.GradleJavaProcessExecutor)2 VariantScope (com.android.build.gradle.internal.scope.VariantScope)2 DefaultDexOptions (com.android.builder.core.DefaultDexOptions)2 VariantConfiguration (com.android.builder.core.VariantConfiguration)2 DexingType (com.android.builder.dexing.DexingType)2 AtlasMultiDexListTransform (com.taobao.android.builder.tasks.transform.dex.AtlasMultiDexListTransform)2 IOException (java.io.IOException)2 Task (org.gradle.api.Task)2 DataBindingBuilder (android.databinding.tool.DataBindingBuilder)1 QualifiedContent (com.android.build.api.transform.QualifiedContent)1 Transform (com.android.build.api.transform.Transform)1 LibraryVariantOutput (com.android.build.gradle.api.LibraryVariantOutput)1 LibraryCache (com.android.build.gradle.internal.LibraryCache)1 SdkHandler (com.android.build.gradle.internal.SdkHandler)1 TaskContainerAdaptor (com.android.build.gradle.internal.TaskContainerAdaptor)1