use of com.taobao.android.builder.tools.bundleinfo.BundleItem in project atlas by alibaba.
the class AtlasProguardHelper method addParentKeeps.
private static void addParentKeeps(BundleItem bundleItem, Input input, AwbTransform awbTransform, Map<BundleInfo, AwbTransform> bundleInfoAwbTransformMap, AppVariantContext appVariantContext) throws IOException {
Set<AwbBundle> parentBundles = new HashSet<>();
for (BundleItem parent : bundleItem.parents) {
parentBundles.add(bundleInfoAwbTransformMap.get(parent.bundleInfo).getAwbBundle());
for (BundleInfo sub : parent.circles) {
parentBundles.add(bundleInfoAwbTransformMap.get(sub).getAwbBundle());
}
}
if (!parentBundles.isEmpty()) {
List<AwbBundle> bundles = new ArrayList<>(parentBundles);
Collections.sort(bundles, new Comparator<AwbBundle>() {
@Override
public int compare(AwbBundle o1, AwbBundle o2) {
return o1.getName().compareTo(o2.getName());
}
});
File keepFile = generateKeepFile(bundles, appVariantContext.getAwbProguardDir(awbTransform.getAwbBundle()));
input.getParentKeeps().add(keepFile);
}
}
use of com.taobao.android.builder.tools.bundleinfo.BundleItem 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);
}
}
});
}
use of com.taobao.android.builder.tools.bundleinfo.BundleItem in project atlas by alibaba.
the class AtlasProguardHelper method addChildDependency.
private static void addChildDependency(BundleItem bundleItem, Input input, Map<BundleInfo, AwbTransform> bundleInfoAwbTransformMap) throws IOException {
List<String> pkgNames = new ArrayList<>();
input.getAwbBundles().forEach(awbTransform -> pkgNames.add(awbTransform.getAwbBundle().getPackageName()));
sLogger.info("combine to proguard bundles:" + pkgNames.toString());
List<AwbTransform> childTransforms = new ArrayList<>();
sLogger.info("combine to proguard bundles:" + pkgNames.toString());
for (BundleItem child : bundleItem.children) {
if (!pkgNames.contains(child.bundleInfo.getPkgName())) {
childTransforms.add(bundleInfoAwbTransformMap.get(child.bundleInfo));
} else {
sLogger.error(child.bundleInfo.getPkgName() + " in proguard bundles so discard from " + bundleItem.bundleInfo.getPkgName() + "libraries...");
}
for (BundleInfo sub : child.circles) {
if (!pkgNames.contains(sub.getPkgName())) {
childTransforms.add(bundleInfoAwbTransformMap.get(sub));
} else {
sLogger.error(sub.getPkgName() + " in proguard bundles so discard from " + bundleItem.bundleInfo.getPkgName() + " libraries...");
}
}
}
List<AwbBundle> childBundles = new ArrayList<>();
for (AwbTransform child : childTransforms) {
input.getLibraries().addAll(child.getInputLibraries());
// join
childBundles.add(child.getAwbBundle());
}
}
Aggregations