use of com.android.build.gradle.internal.pipeline.TransformTask in project atlas by alibaba.
the class TransformReplacer method replaceDexTransform.
public void replaceDexTransform(AppVariantContext appVariantContext, BaseVariantOutput vod) {
List<TransformTask> baseTransforms = TransformManager.findTransformTaskByTransformType(variantContext, DexTransform.class);
DefaultDexOptions dexOptions = appVariantContext.getAppExtension().getDexOptions();
DexingType dexingType = appVariantContext.getScope().getDexingType();
DexByteCodeConverterHook dexByteCodeConverterHook = new DexByteCodeConverterHook(variantContext, variantContext.getAppVariantOutputContext(ApkDataUtils.get(vod)), LoggerWrapper.getLogger(DexByteCodeConverterHook.class), appVariantContext.getScope().getGlobalScope().getAndroidBuilder().getTargetInfo(), new GradleJavaProcessExecutor(appVariantContext.getProject()), appVariantContext.getProject().getLogger().isEnabled(LogLevel.INFO), new ExtraModelInfo(appVariantContext.getScope().getGlobalScope().getProjectOptions(), appVariantContext.getProject().getLogger()));
for (TransformTask transformTask : baseTransforms) {
DexTransform newTransform = new DexTransform(dexOptions, dexingType, false, appVariantContext.getProject().files(variantContext.getScope().getMainDexListFile()), verifyNotNull(appVariantContext.getScope().getGlobalScope().getAndroidBuilder().getTargetInfo(), "Target Info not set."), dexByteCodeConverterHook, appVariantContext.getScope().getGlobalScope().getAndroidBuilder().getErrorReporter(), variantContext.getScope().getMinSdkVersion().getFeatureLevel());
ReflectUtils.updateField(transformTask, "transform", newTransform);
}
}
use of com.android.build.gradle.internal.pipeline.TransformTask in project atlas by alibaba.
the class TransformReplacer method disableCache.
public void disableCache() {
List<TransformTask> list = null;
if (usingIncrementalDexing(variantContext.getScope())) {
list = TransformManager.findTransformTaskByTransformType(variantContext, MainDexListTransform.class);
} else {
list = TransformManager.findTransformTaskByTransformType(variantContext, MultiDexTransform.class);
}
if (list != null) {
for (TransformTask transformTask : list) {
List<Object> list1 = (List<Object>) ReflectUtils.getField(DefaultTaskOutputs.class, transformTask.getOutputs(), "cacheIfSpecs");
list1.clear();
ReflectUtils.updateField(transformTask.getOutputs(), "upToDateSpec", AndSpec.empty());
}
}
list = TransformManager.findTransformTaskByTransformType(variantContext, AtlasProguardTransform.class);
if (list != null) {
for (TransformTask transformTask : list) {
List<Object> list1 = (List<Object>) ReflectUtils.getField(DefaultTaskOutputs.class, transformTask.getOutputs(), "cacheIfSpecs");
list1.clear();
ReflectUtils.updateField(transformTask.getOutputs(), "upToDateSpec", AndSpec.empty());
}
}
list = TransformManager.findTransformTaskByTransformType(variantContext, DexTransform.class);
if (list != null) {
for (TransformTask transformTask : list) {
List<Object> list1 = (List<Object>) ReflectUtils.getField(DefaultTaskOutputs.class, transformTask.getOutputs(), "cacheIfSpecs");
list1.clear();
ReflectUtils.updateField(transformTask.getOutputs(), "upToDateSpec", AndSpec.empty());
}
}
list = TransformManager.findTransformTaskByTransformType(variantContext, AtlasMultiDexListTransform.class);
if (list != null) {
for (TransformTask transformTask : list) {
List<Object> list1 = (List<Object>) ReflectUtils.getField(DefaultTaskOutputs.class, transformTask.getOutputs(), "cacheIfSpecs");
list1.clear();
ReflectUtils.updateField(transformTask.getOutputs(), "upToDateSpec", AndSpec.empty());
}
}
}
use of com.android.build.gradle.internal.pipeline.TransformTask in project atlas by alibaba.
the class TransformManager method findTransformTaskByTransformType.
public static List<TransformTask> findTransformTaskByTransformType(VariantContext appVariantContext, Class<?> transformClass) {
List<TransformTask> transformTasksList = Lists.newArrayList();
VariantConfiguration config = appVariantContext.getVariantConfiguration();
TaskCollection<TransformTask> transformTasks = appVariantContext.getProject().getTasks().withType(TransformTask.class);
SortedMap<String, TransformTask> transformTaskSortedMap = transformTasks.getAsMap();
String variantName = config.getFullName();
for (String taskName : transformTaskSortedMap.keySet()) {
TransformTask transformTask = transformTaskSortedMap.get(taskName);
if (variantName == transformTask.getVariantName()) {
if (transformTask.getTransform().getClass() == transformClass) {
transformTasksList.add(transformTask);
}
}
}
return transformTasksList;
}
use of com.android.build.gradle.internal.pipeline.TransformTask in project atlas by alibaba.
the class AtlasFeatureTaskManager method runTask.
@Override
public void runTask() {
if (featureExtension.getBaseFeature()) {
return;
}
featureExtension.getFeatureVariants().forEach(featureVariant -> {
FeatureVariantContext featureVariantContext = new FeatureVariantContext((FeatureVariantImpl) featureVariant, project, atlasExtension, featureExtension);
ArtifactCollection allArtifacts = featureVariantContext.getScope().getArtifactCollection(AndroidArtifacts.ConsumedConfigType.RUNTIME_CLASSPATH, AndroidArtifacts.ArtifactScope.EXTERNAL, AndroidArtifacts.ArtifactType.CLASSES);
ArtifactCollection artifacts = featureVariantContext.getScope().getArtifactCollection(AndroidArtifacts.ConsumedConfigType.RUNTIME_CLASSPATH, AndroidArtifacts.ArtifactScope.ALL, AndroidArtifacts.ArtifactType.FEATURE_TRANSITIVE_DEPS);
ArtifactCollection filterArtifacts = new FilteredArtifactCollection(featureVariantContext.getProject(), allArtifacts, artifacts.getArtifactFiles());
List<TransformTask> transformTasks = TransformManager.findTransformTaskByTransformType(featureVariantContext, FixStackFramesTransform.class);
if (transformTasks != null) {
for (TransformTask transformTask : transformTasks) {
try {
Field field = StreamBasedTask.class.getDeclaredField("consumedInputStreams");
Field field1 = StreamBasedTask.class.getDeclaredField("referencedInputStreams");
field1.setAccessible(true);
field.setAccessible(true);
Collection<TransformStream> consumedInputStreams = (Collection<TransformStream>) field.get(transformTask);
Collection<TransformStream> referencedInputStreams = (Collection<TransformStream>) field1.get(transformTask);
for (TransformStream stream : consumedInputStreams) {
if (stream.getContentTypes().contains(QualifiedContent.DefaultContentType.CLASSES) && stream.getScopes().contains(QualifiedContent.Scope.EXTERNAL_LIBRARIES)) {
ReflectUtils.updateField(stream, "fileCollection", filterArtifacts.getArtifactFiles());
ReflectUtils.updateField(stream, "artifactCollection", filterArtifacts);
break;
}
}
for (TransformStream transformStream : referencedInputStreams) {
if (transformStream.getContentTypes().contains(QualifiedContent.DefaultContentType.CLASSES) && transformStream.getScopes().contains(QualifiedContent.Scope.PROVIDED_ONLY)) {
ReflectUtils.updateField(transformStream, "fileCollection", project.files());
// ReflectUtils.updateField(transformStream, "artifactCollection", filterArtifacts);
}
}
} catch (Exception e) {
}
}
}
featureVariantContext.getScope().getProcessResourcesTask().get(new TaskContainerAdaptor(featureVariantContext.getProject().getTasks())).setEnableAapt2(true);
});
featureExtension.getLibraryVariants().forEach(libraryVariant -> {
LibVariantContext libVariantContext = new LibVariantContext((LibraryVariantImpl) libraryVariant, project, atlasExtension, featureExtension);
TBuildType tBuildType = libVariantContext.getBuildType();
if (null != tBuildType) {
try {
new AwoPropHandler().process(tBuildType, atlasExtension.getBundleConfig());
} catch (Exception e) {
throw new GradleException("process awo exception", e);
}
}
AwbGenerator awbGenerator = new AwbGenerator(atlasExtension);
Collection<BaseVariantOutput> list = libVariantContext.getBaseVariant().getOutputs();
if (null != list) {
for (BaseVariantOutput libVariantOutputData : list) {
Zip zipTask = ((LibraryVariantOutput) (libVariantOutputData)).getPackageLibrary();
if (atlasExtension.getBundleConfig().isJarEnabled()) {
new JarExtractTask().generateJarArtifict(zipTask);
}
// Build the awb and extension
// if (atlasExtension.getBundleConfig().isAwbBundle()) {
awbGenerator.generateAwbArtifict(zipTask, libVariantContext);
if (null != tBuildType && (StringUtils.isNotEmpty(tBuildType.getBaseApDependency()) || null != tBuildType.getBaseApFile()) && libraryVariant.getName().equals("debug")) {
atlasExtension.getTBuildConfig().setUseCustomAapt(true);
libVariantContext.setBundleTask(zipTask);
try {
libVariantContext.setAwbBundle(awbGenerator.createAwbBundle(libVariantContext));
} catch (IOException e) {
throw new GradleException("set awb bundle error");
}
}
}
}
});
}
use of com.android.build.gradle.internal.pipeline.TransformTask in project atlas by alibaba.
the class BasePlugin method configureProject.
protected void configureProject() {
extraModelInfo = new ExtraModelInfo(project, isLibrary());
checkGradleVersion();
sdkHandler = new SdkHandler(project, getLogger());
project.afterEvaluate(p -> {
if (!p.getGradle().getStartParameter().isOffline() && AndroidGradleOptions.getUseSdkDownload(p)) {
SdkLibData sdkLibData = SdkLibData.download(getDownloader(), getSettingsController());
dependencyManager.setSdkLibData(sdkLibData);
sdkHandler.setSdkLibData(sdkLibData);
}
});
androidBuilder = new AndroidBuilder(project == project.getRootProject() ? project.getName() : project.getPath(), creator, new GradleProcessExecutor(project), new GradleJavaProcessExecutor(project), extraModelInfo, getLogger(), isVerbose());
dataBindingBuilder = new DataBindingBuilder();
dataBindingBuilder.setPrintMachineReadableOutput(extraModelInfo.getErrorFormatMode() == ExtraModelInfo.ErrorFormatMode.MACHINE_PARSABLE);
project.getPlugins().apply(JavaBasePlugin.class);
jacocoPlugin = project.getPlugins().apply(JacocoPlugin.class);
project.getTasks().getByName("assemble").setDescription("Assembles all variants of all applications and secondary packages.");
// call back on execution. This is called after the whole build is done (not
// after the current project is done).
// This is will be called for each (android) projects though, so this should support
// being called 2+ times.
project.getGradle().addBuildListener(new BuildListener() {
private final LibraryCache libraryCache = LibraryCache.getCache();
@Override
public void buildStarted(Gradle gradle) {
}
@Override
public void settingsEvaluated(Settings settings) {
}
@Override
public void projectsLoaded(Gradle gradle) {
}
@Override
public void projectsEvaluated(Gradle gradle) {
}
@Override
public void buildFinished(BuildResult buildResult) {
ExecutorSingleton.shutdown();
sdkHandler.unload();
ThreadRecorder.get().record(ExecutionType.BASE_PLUGIN_BUILD_FINISHED, project.getPath(), null, new Recorder.Block() {
@Override
public Void call() throws Exception {
PreDexCache.getCache().clear(new File(project.getRootProject().getBuildDir(), FD_INTERMEDIATES + "/dex-cache/cache.xml"), getLogger());
JackConversionCache.getCache().clear(new File(project.getRootProject().getBuildDir(), FD_INTERMEDIATES + "/jack-cache/cache.xml"), getLogger());
libraryCache.unload();
Main.clearInternTables();
return null;
}
});
}
});
project.getGradle().getTaskGraph().addTaskExecutionGraphListener(new TaskExecutionGraphListener() {
@Override
public void graphPopulated(TaskExecutionGraph taskGraph) {
for (Task task : taskGraph.getAllTasks()) {
if (task instanceof TransformTask) {
Transform transform = ((TransformTask) task).getTransform();
if (transform instanceof DexTransform) {
PreDexCache.getCache().load(new File(project.getRootProject().getBuildDir(), FD_INTERMEDIATES + "/dex-cache/cache.xml"));
break;
} else if (transform instanceof JackPreDexTransform) {
JackConversionCache.getCache().load(new File(project.getRootProject().getBuildDir(), FD_INTERMEDIATES + "/jack-cache/cache.xml"));
break;
}
}
}
}
});
}
Aggregations