use of com.android.build.gradle.internal.variant.BaseVariantOutputData in project atlas by alibaba.
the class PreProcessManifestTask method addAwbManifest2Merge.
private void addAwbManifest2Merge() {
AtlasExtension atlasExtension = appVariantContext.getAtlasExtension();
for (final BaseVariantOutputData vod : appVariantContext.getVariantData().getOutputs()) {
ManifestProcessorTask manifestProcessorTask = vod.manifestProcessorTask;
Set<String> notMergedArtifacts = Sets.newHashSet();
if (null != atlasExtension.getManifestOptions() && null != atlasExtension.getManifestOptions().getNotMergedBundles()) {
notMergedArtifacts = atlasExtension.getManifestOptions().getNotMergedBundles();
}
if (manifestProcessorTask instanceof MergeManifests) {
MergeManifests mergeManifests = (MergeManifests) manifestProcessorTask;
VariantScope variantScope = appVariantContext.getScope();
GradleVariantConfiguration config = variantScope.getVariantConfiguration();
AndroidDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(config.getFullName());
if (null == dependencyTree) {
throw new StopExecutionException("DependencyTree cannot be null!");
}
List<? extends AndroidLibrary> awbManifests = ManifestDependencyUtil.getManifestDependencies(dependencyTree.getAwbBundles(), notMergedArtifacts, getLogger());
for (AndroidLibrary manifest : awbManifests) {
getLogger().info("[MTLPlugin]Add manifest:" + manifest.getName() + ",path is:" + manifest.getManifest().getAbsolutePath());
}
//FIXME 不加这一步,每次的getibraries 都会从mapping里去重新计算
mergeManifests.setLibraries(mergeManifests.getLibraries());
mergeManifests.getLibraries().addAll(awbManifests);
}
}
}
use of com.android.build.gradle.internal.variant.BaseVariantOutputData 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);
}
}
});
}
}
}
Aggregations