use of com.android.build.gradle.internal.api.AwbTransform 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());
}
}
use of com.android.build.gradle.internal.api.AwbTransform in project atlas by alibaba.
the class BundleProguarder method doProguard.
public static void doProguard(AppVariantContext appVariantContext, Input input) throws Exception {
Configuration configuration = parseConfiguration(appVariantContext, input);
configuration.dump = input.dump;
if (null == input.printConfiguration) {
configuration.printConfiguration = new File(appVariantContext.getAwbProguardDir(input.getAwbBundles().get(0).getAwbBundle()), "proguard.cfg");
} else {
configuration.printConfiguration = input.printConfiguration;
}
configuration.printSeeds = null;
configuration.dump = null;
configuration.obfuscate = false;
// configuration.optimizationPasses = 1;
configuration.printUsage = input.printUsage;
configuration.printMapping = input.printMapping;
// Execute ProGuard with these options.
ProGuard proGuard = new ProGuard(configuration);
System.out.println(">>> start to do proguard");
proGuard.execute();
System.out.println("<<< end proguard");
ClassPool classPool = (ClassPool) ReflectUtils.getField(proGuard, "programClassPool");
Map<String, ClazzRefInfo> clazzRefInfoMap = BundleProguardDumper.dump(proGuard, input.getDefaultLibraryClasses());
// Fileoutputs
for (AwbTransform awbTransform : input.getAwbBundles()) {
if (!awbTransform.getAwbBundle().isMainBundle()) {
AwbBundle awbBundle = awbTransform.getAwbBundle();
File fileOut = new File(appVariantContext.getAwbProguardDir(awbBundle), "keep.json");
fileOut.delete();
fileOut.getParentFile().mkdirs();
FileUtils.write(fileOut, JSON.toJSONString(clazzRefInfoMap));
awbBundle.setKeepProguardFile(fileOut);
}
}
}
use of com.android.build.gradle.internal.api.AwbTransform in project atlas by alibaba.
the class AwbProguardConfiguration method printConfigFile.
/**
* Print the proguard config file to the specified file
*
* @param outConfigFile
*/
public List<File> printConfigFile(File outConfigFile) throws IOException {
List<String> configs = Lists.newArrayList();
List<File> bundleFiles = Lists.newArrayList();
// awbProguard for no lib, convenient for predex
for (AwbTransform awbTransform : awbTransforms) {
List<File> inputLibraries = Lists.newArrayList();
String name = awbTransform.getAwbBundle().getName();
File obuscateDir = new File(awbObfuscatedDir, awbTransform.getAwbBundle().getName());
obuscateDir.mkdirs();
if (null != awbTransform.getInputDirs() && awbTransform.getInputDirs().size() > 0) {
for (File dir : awbTransform.getInputDirs()) {
if (dir.exists()) {
configs.add(INJARS_OPTION + " " + dir.getAbsolutePath());
File obsJar = new File(obuscateDir, "inputdir_" + OBUSCATED_JAR);
inputLibraries.add(obsJar);
configs.add(OUTJARS_OPTION + " " + obsJar.getAbsolutePath());
}
}
}
Set<String> classNames = new HashSet<>();
for (File inputLibrary : awbTransform.getInputLibraries()) {
configs.add(INJARS_OPTION + " " + inputLibrary.getAbsolutePath());
bundleFiles.add(inputLibrary);
String fileName = inputLibrary.getName();
if (classNames.contains(fileName)) {
fileName = "a" + classNames.size() + "_" + fileName;
}
classNames.add(fileName);
File obsJar = new File(obuscateDir, fileName);
inputLibraries.add(obsJar);
configs.add(OUTJARS_OPTION + " " + obsJar.getAbsolutePath());
}
// configs.add();
awbTransform.setInputFiles(inputLibraries);
awbTransform.getInputDirs().clear();
awbTransform.getInputLibraries().clear();
appVariantOutputContext.getAwbTransformMap().put(name, awbTransform);
}
FileUtils.writeLines(outConfigFile, configs);
return bundleFiles;
}
use of com.android.build.gradle.internal.api.AwbTransform in project atlas by alibaba.
the class BuildAtlasEnvTask method fillAwbSolibs.
private void fillAwbSolibs(String name, String moudleName, AwbBundle awbBundle) {
AwbTransform awbTransform = appVariantOutputContext.getAwbTransformMap().get(awbBundle.getName());
File id = null;
if ((id = allSolibs.get(name)) == null) {
id = allSolibs.get(moudleName);
}
if (id != null) {
awbTransform.getLibraryJniLibsInputDir().add(id);
}
}
use of com.android.build.gradle.internal.api.AwbTransform in project atlas by alibaba.
the class BuildAtlasEnvTask method fillAwbAllJavaRes.
private void fillAwbAllJavaRes(String name, String moudleName, AwbBundle awbBundle) {
AwbTransform awbTransform = appVariantOutputContext.getAwbTransformMap().get(awbBundle.getName());
File id = null;
if ((id = allJavaRes.get(name)) == null) {
id = allJavaRes.get(moudleName);
}
if (id != null) {
awbTransform.getLibraryResourcesInutDir().add(id);
}
}
Aggregations