use of com.taobao.android.builder.dependency.AndroidDependencyTree in project atlas by alibaba.
the class AwbProguradHook method hookProguardTask.
/**
* hook混淆的任务,加入awb的混淆配置
*
* @param appVariantContext
*/
public void hookProguardTask(final AppVariantContext appVariantContext) {
final VariantScope variantScope = appVariantContext.getScope();
List<TransformTask> proguaradTransformTasks = getTransformTaskByTransformType(appVariantContext, ProGuardTransform.class);
for (TransformTask proguaradTransformTask : proguaradTransformTasks) {
final ProGuardTransform proGuardTransform = (ProGuardTransform) proguaradTransformTask.getTransform();
if (null != proGuardTransform) {
proguaradTransformTask.doFirst(new Action<Task>() {
@Override
public void execute(Task task) {
GlobalScope globalScope = variantScope.getGlobalScope();
File proguardOut = new File(Joiner.on(File.separatorChar).join(String.valueOf(globalScope.getBuildDir()), FD_OUTPUTS, "mapping", variantScope.getVariantConfiguration().getDirName()));
//为了方便排查,先把configuration打印到目录
proGuardTransform.printconfiguration(new File(proguardOut, "tmp_config.cfg"));
final File outConfigFile = new File(proguardOut, "awb_config.cfg");
//增加awb的配置
AndroidDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(variantScope.getVariantConfiguration().getFullName());
if (null == dependencyTree) {
throw new StopExecutionException("DependencyTree cannot be null!");
}
if (dependencyTree.getAwbBundles().size() > 0) {
BaseVariantOutputData vod = appVariantContext.getVariantData().getOutputs().get(0);
AppVariantOutputContext appVariantOutputContext = getAppVariantOutputContext(appVariantContext, vod);
File awbObfuscatedDir = new File(globalScope.getIntermediatesDir(), "/classes-proguard/" + variantScope.getVariantConfiguration().getDirName());
AwbProguardConfiguration awbProguardConfiguration = new AwbProguardConfiguration(appVariantOutputContext.getAwbTransformMap().values(), awbObfuscatedDir, appVariantOutputContext);
try {
awbProguardConfiguration.printConfigFile(outConfigFile);
} catch (IOException e) {
throw new GradleException("", e);
}
proGuardTransform.setConfigurationFiles(new Supplier<Collection<File>>() {
@Override
public Collection<File> get() {
Set<File> proguardFiles = new HashSet<File>();
((HashSet<File>) proguardFiles).add(outConfigFile);
return proguardFiles;
}
});
}
File mappingFile = null;
if (null != appVariantContext.apContext.getApExploredFolder() && appVariantContext.apContext.getApExploredFolder().exists()) {
mappingFile = new File(appVariantContext.apContext.getApExploredFolder(), "mapping.txt");
} else {
mappingFile = new File(appVariantContext.getScope().getGlobalScope().getProject().getProjectDir(), "mapping.txt");
}
if (null != mappingFile && mappingFile.exists()) {
proGuardTransform.applyTestedMapping(mappingFile);
}
}
});
}
}
}
use of com.taobao.android.builder.dependency.AndroidDependencyTree in project atlas by alibaba.
the class ApkFileListUtils method recordApkFileInfos.
/**
* 记录apk文件的资源信息
*/
public static void recordApkFileInfos(AppVariantContext appVariantContext) {
if (inited) {
return;
}
inited = true;
List<File> mainBundleResFolders = new ArrayList<File>();
mainBundleResFolders.add(appVariantContext.getScope().getVariantData().mergeResourcesTask.getOutputDir());
prepareApkFileList(appVariantContext.getScope().getVariantData().mergeAssetsTask.getOutputDir(), "assets");
for (File resFolder : mainBundleResFolders) {
prepareApkFileList(resFolder, "res");
}
// 记录各自bundle的资源信息
AndroidDependencyTree 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);
prepareApkFileList(mergeResFolder, "res", awbName);
}
}
use of com.taobao.android.builder.dependency.AndroidDependencyTree in project atlas by alibaba.
the class BundleInfoUtils method setupAwbBundleInfos.
public static void setupAwbBundleInfos(AppVariantContext appVariantContext) throws IOException, DocumentException {
String apkVersion = appVariantContext.getVariantConfiguration().getVersionName();
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getScope().getVariantConfiguration().getFullName());
/**
* name 是artifictId
*/
Map<String, BundleInfo> bundleInfoMap = getBundleInfoMap(appVariantContext);
for (AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
update(awbBundle, bundleInfoMap, appVariantContext, apkVersion);
}
}
use of com.taobao.android.builder.dependency.AndroidDependencyTree 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);
}
// 1. 首先添加主bundle
ArtifactBundleInfo mainBundleInfo = getMainArtifactBundInfo(mainfestFile);
mainBundleInfo.setBaseVersion(apVersion);
mainBundleInfo.setMainBundle(true);
mainBundleInfo.setVersion(appVariantOutputContext.getVariantContext().getVariantConfiguration().getVersionName());
if (dependencyDiff.getMainDexDiffs().size() > 0) {
mainBundleInfo.setDiffType(DiffType.MODIFY);
} else {
mainBundleInfo.setDiffType(DiffType.NONE);
}
artifactBundleInfos.add(mainBundleInfo);
// 2. 添加各自的bundle
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantOutputContext.getVariantContext().getVariantConfiguration().getFullName());
for (AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
BundleInfo bundleInfo = awbBundle.bundleInfo;
ArtifactBundleInfo awbBundleInfo = new ArtifactBundleInfo();
awbBundleInfo.setMainBundle(false);
awbBundleInfo.setDependency(bundleInfo.getDependency());
awbBundleInfo.setPkgName(bundleInfo.getPkgName());
awbBundleInfo.setApplicationName(bundleInfo.getApplicationName());
awbBundleInfo.setArtifactId(awbBundle.getResolvedCoordinates().getArtifactId());
awbBundleInfo.setName(bundleInfo.getName());
String version = bundleInfo.getVersion();
if (version.indexOf("@") > 0) {
String[] arr = version.split("@");
version = arr[arr.length - 1];
}
awbBundleInfo.setVersion(version);
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);
}
artifactBundleInfos.add(awbBundleInfo);
}
return artifactBundleInfos;
}
Aggregations