use of com.taobao.android.builder.dependency.AtlasDependencyTree in project atlas by alibaba.
the class DiffBundleInfoTask method getArtifactBundleInfo.
private Set<ArtifactBundleInfo> getArtifactBundleInfo(DependencyDiff dependencyDiff, File mainfestFile, File apDir) throws IOException, DocumentException {
Set<ArtifactBundleInfo> artifactBundleInfos = new HashSet<ArtifactBundleInfo>();
if (null == apDir) {
throw new GradleException("No Ap dependency found!");
}
File apManifest = new File(apDir, "AndroidManifest.xml");
String apVersion = null;
try {
apVersion = ManifestFileUtils.getVersionName(apManifest);
} catch (Exception e) {
throw new GradleException(e.getMessage(), e);
}
Map<String, String> tagMap = new HashMap<>();
JSONObject jsonObject = (JSONObject) JSON.parse(FileUtils.readFileToString(new File(apDir, "atlasFrameworkProperties.json")));
JSONArray jsonArray = jsonObject.getJSONArray("bundleInfo");
for (JSONObject obj : jsonArray.toArray(new JSONObject[0])) {
tagMap.put(obj.getString("pkgName"), obj.getString("unique_tag"));
}
// 2. Add your own bundle
AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantOutputContext.getVariantContext().getVariantConfiguration().getFullName());
List<AwbBundle> modifyMbundles = new ArrayList<>();
for (AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
BundleInfo bundleInfo = awbBundle.bundleInfo;
ArtifactBundleInfo awbBundleInfo = new ArtifactBundleInfo();
awbBundleInfo.setMainBundle(false);
awbBundleInfo.setDependency(newDependency(bundleInfo.getDependency(), appVariantOutputContext.getVariantContext()));
awbBundleInfo.setPkgName(bundleInfo.getPkgName());
awbBundleInfo.setApplicationName(bundleInfo.getApplicationName());
awbBundleInfo.setArtifactId(awbBundle.getResolvedCoordinates().getArtifactId());
awbBundleInfo.setName(bundleInfo.getName());
// History bundle's tag todo
awbBundleInfo.setSrcUnitTag(tagMap.get(bundleInfo.getPkgName()));
awbBundleInfo.setUnitTag(bundleInfo.getUnique_tag());
String version = bundleInfo.getVersion();
if (version.indexOf("@") > 0) {
String[] arr = version.split("@");
version = arr[arr.length - 1];
}
awbBundleInfo.setVersion(version);
// TODO
bundleInfo.getUnique_tag();
String libBundleName = getBundleName(awbBundle);
if (dependencyDiff.getAwbDiffs().contains(libBundleName)) {
if (dependencyDiff.getNewAwbs().contains(libBundleName)) {
awbBundleInfo.setDiffType(DiffType.ADD);
} else {
awbBundleInfo.setDiffType(DiffType.MODIFY);
}
} else {
awbBundleInfo.setDiffType(DiffType.NONE);
}
if (awbBundle.isMBundle) {
if (awbBundleInfo.getDiffType() == DiffType.ADD || awbBundleInfo.getDiffType() == DiffType.MODIFY) {
modifyMbundles.add(awbBundle);
}
continue;
}
artifactBundleInfos.add(awbBundleInfo);
}
// 1. First add the main bundle
ArtifactBundleInfo mainBundleInfo = getMainArtifactBundInfo(mainfestFile);
mainBundleInfo.setBaseVersion(apVersion);
mainBundleInfo.setMainBundle(true);
mainBundleInfo.setVersion(appVariantOutputContext.getVariantContext().getVariantConfiguration().getVersionName());
if (dependencyDiff.getMainDexDiffs().size() > 0 || modifyMbundles.size() > 0) {
mainBundleInfo.setDiffType(DiffType.MODIFY);
} else {
mainBundleInfo.setDiffType(DiffType.NONE);
}
mainBundleInfo.setSrcUnitTag(jsonObject.getString("unit_tag"));
mainBundleInfo.setUnitTag(appVariantOutputContext.getVariantContext().unit_tag);
artifactBundleInfos.add(mainBundleInfo);
return artifactBundleInfos;
}
use of com.taobao.android.builder.dependency.AtlasDependencyTree 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.dependency.AtlasDependencyTree in project atlas by alibaba.
the class AtlasProguardHelper method applyBundleKeeps.
public static void applyBundleKeeps(final AppVariantContext appVariantContext, ProGuardTransform proGuardTransform) {
Set<File> proguardFiles = new HashSet<File>();
GlobalScope globalScope = appVariantContext.getScope().getGlobalScope();
// Add awb configuration
AtlasDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getVariantConfiguration().getFullName());
for (AwbBundle awbBundle : dependencyTree.getAwbBundles()) {
if (null != awbBundle.getKeepProguardFile() && awbBundle.getKeepProguardFile().exists()) {
proguardFiles.add(awbBundle.getKeepProguardFile());
} else {
appVariantContext.getProject().getLogger().error("missing " + awbBundle.getKeepProguardFile().getAbsolutePath());
}
}
proGuardTransform.setConfigurationFiles(appVariantContext.getScope().getGlobalScope().getProject().files(proguardFiles));
}
use of com.taobao.android.builder.dependency.AtlasDependencyTree in project atlas by alibaba.
the class ApkFileListUtils method recordApkFileInfos.
/**
* Records resource information for apk files
*/
public static ApkFiles recordApkFileInfos(AppVariantContext appVariantContext) {
ApkFiles apkFiles = new ApkFiles();
List<File> mainBundleResFolders = new ArrayList<File>();
mainBundleResFolders.add(appVariantContext.getScope().getVariantData().mergeResourcesTask.getOutputDir());
prepareApkFileList(appVariantContext.getScope().getVariantData().mergeAssetsTask.getOutputDir(), "assets", apkFiles);
for (File resFolder : mainBundleResFolders) {
prepareApkFileList(resFolder, "res", apkFiles);
}
// Record the resource information for each bundle
AtlasDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getScope().getVariantConfiguration().getFullName());
if (null == dependencyTree) {
throw new StopExecutionException("DependencyTree cannot be null!");
}
List<AwbBundle> libs = dependencyTree.getAwbBundles();
for (AwbBundle awbLib : libs) {
File mergeAssertFolder = appVariantContext.getMergeAssets(awbLib);
File mergeResFolder = appVariantContext.getMergeResources(awbLib);
String awbName = awbLib.getName();
prepareApkFileList(mergeAssertFolder, "assets", awbName, apkFiles);
prepareApkFileList(mergeResFolder, "res", awbName, apkFiles);
}
return apkFiles;
}
use of com.taobao.android.builder.dependency.AtlasDependencyTree in project atlas by alibaba.
the class BundleInfoUtils method setupAwbBundleInfos.
public static void setupAwbBundleInfos(AppVariantContext appVariantContext) throws IOException, DocumentException {
String apkVersion = appVariantContext.getVariantConfiguration().getVersionName();
AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getScope().getVariantConfiguration().getFullName());
/**
* name Is artifictId
*/
Map<String, BundleInfo> bundleInfoMap = getBundleInfoMap(appVariantContext);
String baseVersion = apkVersion;
if (null != appVariantContext.apContext && null != appVariantContext.apContext.getBaseManifest() && appVariantContext.apContext.getBaseManifest().exists()) {
baseVersion = ManifestFileUtils.getVersionName(appVariantContext.apContext.getBaseManifest());
}
for (AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
update(awbBundle, bundleInfoMap, appVariantContext, apkVersion, baseVersion);
if (appVariantContext.getAtlasExtension().getTBuildConfig().getDisabledBundleDependency()) {
awbBundle.bundleInfo.getDependency().clear();
}
}
}
Aggregations