Search in sources :

Example 1 with BundleItemRunner

use of com.taobao.android.builder.tools.bundleinfo.BundleItemRunner in project atlas by alibaba.

the class AtlasProguardHelper method doBundleProguard.

public static void doBundleProguard(final AppVariantContext appVariantContext, List<File> mainDexJars) throws Exception {
    Profiler.enter("preparebundleproguard");
    VariantScope variantScope = appVariantContext.getScope();
    AtlasDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(variantScope.getVariantConfiguration().getFullName());
    if (dependencyTree.getAwbBundles().isEmpty()) {
        return;
    }
    List<File> libs = new ArrayList<>(appVariantContext.getScope().getGlobalScope().getAndroidBuilder().getBootClasspath(true));
    // All dependent classes
    Profiler.enter("getDefaultClasses");
    Set<String> defaultLibClasses = getClassList(libs);
    Profiler.release();
    libs.addAll(mainDexJars);
    // Get the basic proguard configuration
    List<File> defaultProguardFiles = new ArrayList<>(appVariantContext.getVariantConfiguration().getBuildType().getProguardFiles());
    Collections.sort(defaultProguardFiles);
    BaseVariantOutput vod = (BaseVariantOutput) appVariantContext.getVariantOutputData().iterator().next();
    AppVariantOutputContext appVariantOutputContext = appVariantContext.getAppVariantOutputContext(ApkDataUtils.get(vod));
    int parallelCount = appVariantContext.getAtlasExtension().getTBuildConfig().getProguardParallelCount();
    // //FIXME
    // parallelCount = 1;
    Map<BundleInfo, AwbTransform> bundleInfoAwbTransformMap = new HashMap<>();
    for (AwbTransform awbTransform : appVariantOutputContext.getAwbTransformMap().values()) {
        bundleInfoAwbTransformMap.put(awbTransform.getAwbBundle().bundleInfo, awbTransform);
    }
    Profiler.release();
    BundleGraphExecutor.execute(new ArrayList<>(bundleInfoAwbTransformMap.keySet()), parallelCount, new BundleItemRunner() {

        @Override
        public void execute(BundleItem bundleItem) {
            try {
                Input input = new Input();
                AwbTransform awbTransform = bundleInfoAwbTransformMap.get(bundleItem.bundleInfo);
                input.getAwbBundles().add(awbTransform);
                for (BundleInfo sub : bundleItem.circles) {
                    input.getAwbBundles().add(bundleInfoAwbTransformMap.get(sub));
                }
                input.getDefaultProguardFiles().addAll(defaultProguardFiles);
                input.getLibraries().addAll(libs);
                input.getDefaultLibraryClasses().addAll(defaultLibClasses);
                input.printConfiguration = new File(appVariantContext.getAwbProguardDir(input.getAwbBundles().get(0).getAwbBundle()), "proguard.cfg");
                input.printUsage = new File(appVariantContext.getAwbProguardDir(input.getAwbBundles().get(0).getAwbBundle()), "usage.cfg");
                addLibraryProguardFiles(appVariantContext, input);
                addChildDependency(bundleItem, input, bundleInfoAwbTransformMap);
                addParentKeeps(bundleItem, input, awbTransform, bundleInfoAwbTransformMap, appVariantContext);
                BundleProguarder.execute(appVariantContext, input);
            } catch (Exception e) {
                e.printStackTrace();
                throw new GradleException("proguard " + bundleItem.bundleInfo.getPkgName(), e);
            }
        }
    });
}
Also used : VariantScope(com.android.build.gradle.internal.scope.VariantScope) BundleItemRunner(com.taobao.android.builder.tools.bundleinfo.BundleItemRunner) AppVariantOutputContext(com.android.build.gradle.internal.api.AppVariantOutputContext) AtlasDependencyTree(com.taobao.android.builder.dependency.AtlasDependencyTree) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) BaseVariantOutput(com.android.build.gradle.api.BaseVariantOutput) Input(com.taobao.android.builder.tools.proguard.domain.Input) BundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BundleInfo) BundleItem(com.taobao.android.builder.tools.bundleinfo.BundleItem) AwbTransform(com.android.build.gradle.internal.api.AwbTransform) GradleException(org.gradle.api.GradleException) JarFile(java.util.jar.JarFile) File(java.io.File)

Aggregations

BaseVariantOutput (com.android.build.gradle.api.BaseVariantOutput)1 AppVariantOutputContext (com.android.build.gradle.internal.api.AppVariantOutputContext)1 AwbTransform (com.android.build.gradle.internal.api.AwbTransform)1 VariantScope (com.android.build.gradle.internal.scope.VariantScope)1 AtlasDependencyTree (com.taobao.android.builder.dependency.AtlasDependencyTree)1 BundleItem (com.taobao.android.builder.tools.bundleinfo.BundleItem)1 BundleItemRunner (com.taobao.android.builder.tools.bundleinfo.BundleItemRunner)1 BundleInfo (com.taobao.android.builder.tools.bundleinfo.model.BundleInfo)1 Input (com.taobao.android.builder.tools.proguard.domain.Input)1 File (java.io.File)1 IOException (java.io.IOException)1 JarFile (java.util.jar.JarFile)1 GradleException (org.gradle.api.GradleException)1