use of com.android.build.gradle.internal.pipeline.TransformTask 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.android.build.gradle.internal.pipeline.TransformTask in project atlas by alibaba.
the class TransformReplacer method repalaceSomeInstantTransform.
public void repalaceSomeInstantTransform(BaseVariantOutput vod) {
variantContext.getProject().getTasks().withType(FastDeployRuntimeExtractorTask.class).forEach(fastDeployRuntimeExtractorTask -> fastDeployRuntimeExtractorTask.setEnabled(false));
List<TransformTask> baseTransforms = TransformManager.findTransformTaskByTransformType(variantContext, InstantRunDependenciesApkBuilder.class);
if (baseTransforms != null && baseTransforms.size() > 0) {
for (TransformTask transformTask : baseTransforms) {
transformTask.setEnabled(false);
}
}
List<TransformTask> transforms = TransformManager.findTransformTaskByTransformType(variantContext, InstantRunTransform.class);
if (transforms != null && transforms.size() > 0) {
for (TransformTask transformTask : transforms) {
TaobaoInstantRunTransform taobaoInstantRunTransform = new TaobaoInstantRunTransform(variantContext, variantContext.getAppVariantOutputContext(ApkDataUtils.get(vod)), WaitableExecutor.useGlobalSharedThreadPool(), variantContext.getScope());
ReflectUtils.updateField(transformTask, "transform", taobaoInstantRunTransform);
}
}
List<TransformTask> verifytransforms = TransformManager.findTransformTaskByTransformType(variantContext, InstantRunVerifierTransform.class);
if (verifytransforms != null && verifytransforms.size() > 0) {
for (TransformTask transformTask : verifytransforms) {
transformTask.setEnabled(false);
}
}
List<TransformTask> transforms1 = TransformManager.findTransformTaskByTransformType(variantContext, ExtractJarsTransform.class);
if (transforms1 != null && transforms1.size() > 0) {
for (TransformTask transformTask : transforms1) {
TaobaoExtractJarsTransform taobaoExtractJarsTransform = new TaobaoExtractJarsTransform(variantContext, variantContext.getAppVariantOutputContext(ApkDataUtils.get(vod)), ImmutableSet.of(QualifiedContent.DefaultContentType.CLASSES), ImmutableSet.of(QualifiedContent.Scope.SUB_PROJECTS));
ReflectUtils.updateField(transformTask, "transform", taobaoExtractJarsTransform);
}
}
List<TransformTask> transforms2 = TransformManager.findTransformTaskByTransformType(variantContext, InstantRunDex.class);
if (transforms2 != null && transforms2.size() > 0) {
for (TransformTask transformTask : transforms2) {
TaobaoInstantRunDex taobaoInstantRunDex = new TaobaoInstantRunDex(variantContext, variantContext.getScope(), variantContext.getScope().getGlobalScope().getAndroidBuilder().getDexByteCodeConverter(), (DexOptions) ReflectUtils.getField(transformTask.getTransform(), "dexOptions"), variantContext.getProject().getLogger(), (Integer) ReflectUtils.getField(transformTask.getTransform(), "minSdkForDx"), vod);
ReflectUtils.updateField(transformTask, "transform", taobaoInstantRunDex);
}
}
List<TransformTask> transformTaskList = TransformManager.findTransformTaskByTransformType(variantContext, InstantRunSliceSplitApkBuilder.class);
if (transformTaskList != null && transformTaskList.size() > 0) {
for (TransformTask transformTask : transformTaskList) {
transformTask.setEnabled(false);
}
}
List<TransformTask> transformTaskList1 = TransformManager.findTransformTaskByTransformType(variantContext, InstantRunSlicer.class);
if (transformTaskList1 != null && transformTaskList1.size() > 0) {
for (TransformTask transformTask : transformTaskList1) {
transformTask.setEnabled(false);
// TaobaoInstantRunSlicer taobaoInstantRunSlicer = new TaobaoInstantRunSlicer(variantContext.getProject().getLogger(),variantContext.getScope());
// ReflectUtils.updateField(transformTask,"transform",taobaoInstantRunSlicer);
}
}
}
use of com.android.build.gradle.internal.pipeline.TransformTask in project atlas by alibaba.
the class TransformReplacer method replaceFixStackFramesTransform.
public void replaceFixStackFramesTransform(BaseVariantOutput vod) {
List<TransformTask> baseTransforms = TransformManager.findTransformTaskByTransformType(variantContext, FixStackFramesTransform.class);
for (TransformTask transformTask : baseTransforms) {
FixStackFramesTransform transform = (FixStackFramesTransform) transformTask.getTransform();
AtlasFixStackFramesTransform atlasFixStackFramesTransform = new AtlasFixStackFramesTransform(variantContext.getAppVariantOutputContext(ApkDataUtils.get(vod)), (Supplier<List<File>>) ReflectUtils.getField(transform, "androidJarClasspath"), (List<Path>) ReflectUtils.getField(transform, "compilationBootclasspath"), (FileCache) ReflectUtils.getField(transform, "userCache"));
atlasFixStackFramesTransform.oldTransform = transform;
ReflectUtils.updateField(transformTask, "transform", atlasFixStackFramesTransform);
}
}
use of com.android.build.gradle.internal.pipeline.TransformTask in project atlas by alibaba.
the class TransformReplacer method replaceMultiDexListTransform.
public void replaceMultiDexListTransform() {
List<TransformTask> list = null;
FastMultiDexer fastMultiDexer = new FastMultiDexer(variantContext);
if (usingIncrementalDexing(variantContext.getScope())) {
list = TransformManager.findTransformTaskByTransformType(variantContext, MainDexListTransform.class);
} else {
list = TransformManager.findTransformTaskByTransformType(variantContext, MultiDexTransform.class);
}
if (list.size() > 0 && fastMultiDexer.isFastMultiDexEnabled()) {
com.android.build.gradle.internal.dsl.DexOptions dexOptions = variantContext.getScope().getGlobalScope().getExtension().getDexOptions();
AtlasMultiDexListTransform atlasMultiDexListTransform = new AtlasMultiDexListTransform(variantContext.getScope(), dexOptions);
for (TransformTask transformTask : list) {
ReflectUtils.updateField(transformTask, "transform", atlasMultiDexListTransform);
transformTask.doFirst(task -> AtlasBuildContext.androidBuilderMap.get(task.getProject()).multiDexer = (AtlasBuilder.MultiDexer) fastMultiDexer);
transformTask.doLast(task -> AtlasBuildContext.androidBuilderMap.get(task.getProject()).multiDexer = null);
}
}
}
use of com.android.build.gradle.internal.pipeline.TransformTask in project atlas by alibaba.
the class TransformReplacer method replaceMergeJavaResourcesTransform.
public void replaceMergeJavaResourcesTransform(AppVariantContext appVariantContext, BaseVariantOutput vod) {
List<TransformTask> baseTransforms = TransformManager.findTransformTaskByTransformType(variantContext, MergeJavaResourcesTransform.class);
for (TransformTask transformTask : baseTransforms) {
MergeJavaResourcesTransform transform = (MergeJavaResourcesTransform) transformTask.getTransform();
PackagingOptions packagingOptions = (PackagingOptions) ReflectUtils.getField(transform, "packagingOptions");
packagingOptions.exclude("**.aidl");
packagingOptions.exclude("**.cfg");
Set<? super QualifiedContent.Scope> mergeScopes = (Set<? super QualifiedContent.Scope>) ReflectUtils.getField(transform, "mergeScopes");
Set<QualifiedContent.ContentType> mergedType = (Set<QualifiedContent.ContentType>) ReflectUtils.getField(transform, "mergedType");
String name = (String) ReflectUtils.getField(transform, "name");
AtlasMergeJavaResourcesTransform atlasMergeJavaResourcesTransform = new AtlasMergeJavaResourcesTransform(appVariantContext.getAppVariantOutputContext(ApkDataUtils.get(vod)), packagingOptions, mergeScopes, mergedType.iterator().next(), name, appVariantContext.getScope());
ReflectUtils.updateField(transformTask, "transform", atlasMergeJavaResourcesTransform);
}
}
Aggregations