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);
}
}
});
}
Aggregations