use of com.android.build.gradle.internal.pipeline.OriginalStream in project atlas by alibaba.
the class AtlasProguardTransform method doMainBundleProguard.
private void doMainBundleProguard(TransformInvocation invocation) throws Exception {
// apply bundle Inout
Profiler.enter("bundleKeep");
File bundleKeep = AtlasProguardHelper.generateBundleKeepCfg(appVariantContext);
Profiler.release();
Input input = new Input();
AwbBundle awbBundle = new AwbBundle();
awbBundle.getAndroidLibraries().addAll(AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getVariantName()).getMainBundle().getAndroidLibraries());
AwbTransform awbTransform = new AwbTransform(awbBundle);
input.getAwbBundles().add(awbTransform);
List<File> unProguardJars = new ArrayList<>();
// Enter the input
for (TransformInput transformInput : invocation.getInputs()) {
for (JarInput jarInput : transformInput.getJarInputs()) {
File file = jarInput.getFile();
if (file.getName().startsWith("combined-rmerge")) {
unProguardJars.add(file);
} else if (AtlasBuildContext.atlasMainDexHelperMap.get(appVariantContext.getVariantName()).inMainDex(jarInput)) {
awbTransform.getInputLibraries().add(file);
}
}
for (DirectoryInput directoryInput : transformInput.getDirectoryInputs()) {
if (AtlasBuildContext.atlasMainDexHelperMap.get(appVariantContext.getVariantName()).getInputDirs().contains(directoryInput.getFile())) {
awbTransform.getInputLibraries().add(directoryInput.getFile());
}
}
}
// inputting librarys
input.getLibraries().addAll(appVariantContext.getScope().getGlobalScope().getAndroidBuilder().getBootClasspath(true));
input.getLibraries().addAll(unProguardJars);
// The default proguard configuration
input.getDefaultProguardFiles().addAll(defaultProguardFiles);
// bundle keeps
input.getParentKeeps().add(bundleKeep);
File outFile = invocation.getOutputProvider().getContentLocation("main", getOutputTypes(), getScopes(), Format.JAR);
outFile.delete();
input.proguardOutputDir = invocation.getOutputProvider().getContentLocation("main", getOutputTypes(), getScopes(), Format.DIRECTORY);
input.printMapping = (File) ReflectUtils.getField(oldTransform, "printMapping");
input.dump = (File) ReflectUtils.getField(oldTransform, "dump");
input.printSeeds = (File) ReflectUtils.getField(oldTransform, "printSeeds");
input.printUsage = (File) ReflectUtils.getField(oldTransform, "printUsage");
input.printConfiguration = new File(appVariantContext.getProject().getBuildDir(), "outputs/proguard.cfg");
Profiler.enter("executeproguard");
BundleProguarder.execute(appVariantContext, input);
transformInput(input);
Profiler.release();
for (File jar : unProguardJars) {
File to = invocation.getOutputProvider().getContentLocation(FileNameUtils.getUniqueJarName(jar), getOutputTypes(), getScopes(), Format.JAR);
FileUtils.copyFile(jar, to);
}
OriginalStream originalStream = OriginalStream.builder(appVariantContext.getProject(), "proguard-classes").addContentTypes(com.android.build.gradle.internal.pipeline.TransformManager.CONTENT_CLASS).addScope(QualifiedContent.Scope.PROJECT).setFileCollection(appVariantContext.getProject().files(AtlasBuildContext.atlasMainDexHelperMap.get(appVariantContext.getVariantName()).getAllMainDexJars())).build();
if (nextTransformTask != null) {
Collection consumedInputStreams = (Collection) ReflectUtils.getField(nextTransformTask, "consumedInputStreams");
if (appVariantContext.getAtlasExtension().getTBuildConfig().isFastProguard() && consumedInputStreams != null) {
consumedInputStreams.add(originalStream);
}
}
}
Aggregations