Search in sources :

Example 1 with AppVariantOutputContext

use of com.android.build.gradle.internal.api.AppVariantOutputContext in project atlas by alibaba.

the class AwbProguradHook method getAppVariantOutputContext.

private AppVariantOutputContext getAppVariantOutputContext(AppVariantContext appVariantContext, BaseVariantOutputData vod) {
    AppVariantOutputContext appVariantOutputContext = (AppVariantOutputContext) appVariantContext.getOutputContextMap().get(vod.getFullName());
    if (null == appVariantOutputContext) {
        appVariantOutputContext = new AppVariantOutputContext(vod.getFullName(), appVariantContext, vod.getScope(), vod.variantData);
        appVariantContext.getOutputContextMap().put(vod.getFullName(), appVariantOutputContext);
    }
    return appVariantOutputContext;
}
Also used : AppVariantOutputContext(com.android.build.gradle.internal.api.AppVariantOutputContext)

Example 2 with AppVariantOutputContext

use of com.android.build.gradle.internal.api.AppVariantOutputContext in project atlas by alibaba.

the class MergeManifestAwbsConfigAction method execute.

@Override
public void execute(MtlParallelTask parallelTask) {
    super.execute(parallelTask);
    AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(parallelTask.getVariantName());
    if (null == androidDependencyTree) {
        return;
    }
    List<DefaultTask> tasks = new ArrayList<DefaultTask>();
    AppVariantOutputContext appVariantOutputContext = getAppVariantOutputContext();
    for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
        List<ManifestMerger2.Invoker.Feature> optionalFeatures = ImmutableList.<ManifestMerger2.Invoker.Feature>of();
        MergeAwbManifests.ConfigAction configAction = new MergeAwbManifests.ConfigAction(appVariantOutputContext.getOutputScope(), awbBundle, optionalFeatures, appVariantOutputContext);
        MergeAwbManifests mergeAwbManifests = TaskCreater.create(appVariantContext.getProject(), configAction.getName(), configAction.getType());
        configAction.execute(mergeAwbManifests);
        tasks.add(mergeAwbManifests);
    }
    parallelTask.parallelTask = tasks;
    parallelTask.uniqueTaskName = getName();
}
Also used : ArrayList(java.util.ArrayList) DefaultTask(org.gradle.api.DefaultTask) ManifestMerger2(com.android.manifmerger.ManifestMerger2) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) AppVariantOutputContext(com.android.build.gradle.internal.api.AppVariantOutputContext) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle)

Example 3 with AppVariantOutputContext

use of com.android.build.gradle.internal.api.AppVariantOutputContext 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 4 with AppVariantOutputContext

use of com.android.build.gradle.internal.api.AppVariantOutputContext in project atlas by alibaba.

the class MtlBaseTaskAction method getAppVariantOutputContext.

protected AppVariantOutputContext getAppVariantOutputContext() {
    if (!(variantContext instanceof AppVariantContext)) {
        return null;
    }
    AppVariantContext appVariantContext = (AppVariantContext) variantContext;
    AppVariantOutputContext appVariantOutputContext = (AppVariantOutputContext) appVariantContext.getOutputContextMap().get(baseVariantOutputData.getFullName());
    if (null == appVariantOutputContext) {
        appVariantOutputContext = new AppVariantOutputContext(baseVariantOutputData.getFullName(), appVariantContext, baseVariantOutputData.getScope(), baseVariantOutputData.variantData);
        appVariantContext.getOutputContextMap().put(baseVariantOutputData.getFullName(), appVariantOutputContext);
    }
    return appVariantOutputContext;
}
Also used : AppVariantOutputContext(com.android.build.gradle.internal.api.AppVariantOutputContext) AppVariantContext(com.android.build.gradle.internal.api.AppVariantContext)

Example 5 with AppVariantOutputContext

use of com.android.build.gradle.internal.api.AppVariantOutputContext in project atlas by alibaba.

the class MtlInjectTransform method getAppVariantOutputContext.

protected AppVariantOutputContext getAppVariantOutputContext() {
    AppVariantOutputContext appVariantOutputContext = (AppVariantOutputContext) appVariantContext.getOutputContextMap().get(baseVariantOutputData.getFullName());
    if (null == appVariantOutputContext) {
        appVariantOutputContext = new AppVariantOutputContext(baseVariantOutputData.getFullName(), appVariantContext, baseVariantOutputData.getScope(), baseVariantOutputData.variantData);
        appVariantContext.getOutputContextMap().put(baseVariantOutputData.getFullName(), appVariantOutputContext);
    }
    return appVariantOutputContext;
}
Also used : AppVariantOutputContext(com.android.build.gradle.internal.api.AppVariantOutputContext)

Aggregations

AppVariantOutputContext (com.android.build.gradle.internal.api.AppVariantOutputContext)5 AndroidDependencyTree (com.taobao.android.builder.dependency.AndroidDependencyTree)2 AppVariantContext (com.android.build.gradle.internal.api.AppVariantContext)1 TransformTask (com.android.build.gradle.internal.pipeline.TransformTask)1 GlobalScope (com.android.build.gradle.internal.scope.GlobalScope)1 VariantScope (com.android.build.gradle.internal.scope.VariantScope)1 ProGuardTransform (com.android.build.gradle.internal.transforms.ProGuardTransform)1 BaseVariantOutputData (com.android.build.gradle.internal.variant.BaseVariantOutputData)1 ManifestMerger2 (com.android.manifmerger.ManifestMerger2)1 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)1 AwbProguardConfiguration (com.taobao.android.builder.tasks.app.bundle.AwbProguardConfiguration)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Supplier (java.util.function.Supplier)1 DefaultTask (org.gradle.api.DefaultTask)1 GradleException (org.gradle.api.GradleException)1 Task (org.gradle.api.Task)1 StopExecutionException (org.gradle.api.tasks.StopExecutionException)1