use of com.android.build.gradle.internal.scope.VariantScope in project atlas by alibaba.
the class MergeAwbResourceConfigAction method execute.
@Override
public void execute(MergeResources mergeResourcesTask) {
VariantScope scope = variantContext.getScope();
final BaseVariantData<? extends BaseVariantOutputData> variantData = scope.getVariantData();
final AndroidConfig extension = scope.getGlobalScope().getExtension();
//final VariantConfiguration variantConfig = variantData.getVariantConfiguration();
mergeResourcesTask.setMinSdk(variantData.getVariantConfiguration().getMinSdkVersion().getApiLevel());
mergeResourcesTask.setAndroidBuilder(scope.getGlobalScope().getAndroidBuilder());
mergeResourcesTask.setVariantName(scope.getVariantConfiguration().getFullName());
GlobalScope globalScope = scope.getGlobalScope();
mergeResourcesTask.setIncrementalFolder(scope.getIncrementalDir(getName()));
try {
FieldUtils.writeField(mergeResourcesTask, "variantScope", scope, true);
} catch (IllegalAccessException e) {
throw new GradleException("exception", e);
}
// where blame is useful, and once for packaging where it is not.
if (includeDependencies) {
mergeResourcesTask.setBlameLogFolder(scope.getResourceBlameLogDir());
} else {
// if (variantContext instanceof AppVariantContext) {
// mergeResourcesTask.setBlameLogFolder(((AppVariantContext) variantContext).getAwbBlameLogFolder(awbBundle));
// }
}
mergeResourcesTask.setProcess9Patch(process9Patch);
mergeResourcesTask.setCrunchPng(extension.getAaptOptions().getCruncherEnabled());
VectorDrawablesOptions vectorDrawablesOptions = variantData.getVariantConfiguration().getMergedFlavor().getVectorDrawables();
Set<String> generatedDensities = vectorDrawablesOptions.getGeneratedDensities();
mergeResourcesTask.setGeneratedDensities(Objects.firstNonNull(generatedDensities, Collections.<String>emptySet()));
mergeResourcesTask.setDisableVectorDrawables(vectorDrawablesOptions.getUseSupportLibrary() || mergeResourcesTask.getGeneratedDensities().isEmpty());
//mergeResourcesTask.setUseNewCruncher(extension.getAaptOptions().getUseNewCruncher());
final boolean validateEnabled = AndroidGradleOptions.isResourceValidationEnabled(scope.getGlobalScope().getProject());
mergeResourcesTask.setValidateEnabled(validateEnabled);
ConventionMappingHelper.map(mergeResourcesTask, "inputResourceSets", new Callable<List<ResourceSet>>() {
@Override
public List<ResourceSet> call() throws Exception {
List<ResourceSet> resourceSets = Lists.newArrayList();
List<? extends AndroidLibrary> bundleDeps = awbBundle.getLibraryDependencies();
// the list of dependency must be reversed to use the right overlay order.
for (int n = bundleDeps.size() - 1; n >= 0; n--) {
AndroidLibrary dependency = bundleDeps.get(n);
File resFolder = dependency.getResFolder();
if (resFolder.isDirectory()) {
ResourceSet resourceSet = new ResourceSet(dependency.getFolder().getName(), true);
resourceSet.addSource(resFolder);
resourceSets.add(resourceSet);
}
}
File awbResourceFolder = awbBundle.getResFolder();
if (awbResourceFolder.isDirectory()) {
ResourceSet resourceSet = new ResourceSet(awbBundle.getFolder().getName(), true);
resourceSet.addSource(awbResourceFolder);
resourceSets.add(resourceSet);
}
return resourceSets;
}
});
mergeResourcesTask.setOutputDir(variantContext.getMergeResources(awbBundle));
mergeResourcesTask.setGeneratedPngsOutputDir(variantContext.getPngsOutputDir(awbBundle));
// if (variantContext instanceof AppVariantContext) {
// AppVariantContext appVariantContext = (AppVariantContext) variantContext;
// appVariantContext.getAwbMergeResourceTasks().put(awbBundle.getName(), mergeResourcesTask);
// }
}
use of com.android.build.gradle.internal.scope.VariantScope in project atlas by alibaba.
the class AtlasAppTaskManager method runTask.
@Override
public void runTask() {
appExtension.getApplicationVariants().forEach(new Consumer<ApplicationVariant>() {
@Override
public void accept(ApplicationVariant applicationVariant) {
AppVariantContext appVariantContext = AtlasBuildContext.sBuilderAdapter.appVariantContextFactory.getAppVariantContext(project, applicationVariant);
if (!AtlasBuildContext.atlasMainDexHelperMap.containsKey(appVariantContext.getVariantName())) {
AtlasBuildContext.atlasMainDexHelperMap.put(appVariantContext.getVariantName(), new AtlasMainDexHelper());
}
TransformReplacer transformReplacer = new TransformReplacer(appVariantContext);
repalceAndroidBuilder(applicationVariant);
List<MtlTaskContext> mtlTaskContextList = new ArrayList<MtlTaskContext>();
mtlTaskContextList.add(new MtlTaskContext(appVariantContext.getVariantData().preBuildTask));
mtlTaskContextList.add(new MtlTaskContext(BuildAtlasEnvTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(ScanDupResTask.ConfigActon.class, null));
mtlTaskContextList.add(new MtlTaskContext(LogDependenciesTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(PrepareAPTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(appVariantContext.getVariantData().mergeAssetsTask));
mtlTaskContextList.add(new MtlTaskContext(RenderscriptCompile.class));
mtlTaskContextList.add(new MtlTaskContext(StandardizeLibManifestTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(PrepareBundleInfoTask.ConfigAction.class, null));
if (!atlasExtension.getTBuildConfig().getClassInject() && atlasExtension.isAtlasEnabled()) {
mtlTaskContextList.add(new MtlTaskContext(GenerateAtlasSourceTask.ConfigAction.class, null));
}
mtlTaskContextList.add(new MtlTaskContext(PreparePackageIdsTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(PrepareAaptTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(AidlCompile.class));
mtlTaskContextList.add(new MtlTaskContext(GenerateBuildConfig.class));
mtlTaskContextList.add(new MtlTaskContext(MergeResAwbsConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(MergeAssetAwbsConfigAction.class, null));
if (null != androidExtension.getDataBinding() && androidExtension.getDataBinding().isEnabled() && !appVariantContext.getAtlasExtension().getTBuildConfig().getAllBundlesToMdex()) {
// mtlTaskContextList.add(
// new MtlTaskContext(AwbDataBindingProcessLayoutTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(AwbDataBindingExportBuildInfoTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(AwbDataBindingMergeArtifactsTask.ConfigAction.class, null));
}
mtlTaskContextList.add(new MtlTaskContext(MergeManifests.class));
mtlTaskContextList.add(new MtlTaskContext(MergeManifestAwbsConfigAction.class, null));
// mtlTaskContextList.add(new MtlTaskContext(MergeResV4Dir.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(ProcessAndroidResources.class));
ProcessAndroidResources processAndroidResources = appVariantContext.getScope().getProcessResourcesTask().get(new TaskContainerAdaptor(appVariantContext.getProject().getTasks()));
if (processAndroidResources.isAapt2Enabled()) {
processAndroidResources.doLast(new Action<Task>() {
@Override
public void execute(Task task) {
File processResourcePackageOutputDirectory = appVariantContext.getScope().getProcessResourcePackageOutputDirectory();
File[] files = processResourcePackageOutputDirectory.listFiles((file, name) -> name.endsWith(SdkConstants.DOT_RES));
for (File file : files) {
try {
ResourcePatch.makePatchable(file);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
});
}
mtlTaskContextList.add(new MtlTaskContext(ProcessResAwbsTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(JavacAwbsTask.ConfigAction.class, null));
if (null != androidExtension.getDataBinding() && androidExtension.getDataBinding().isEnabled() && !appVariantContext.getAtlasExtension().getTBuildConfig().getAllBundlesToMdex()) {
mtlTaskContextList.add(new MtlTaskContext(AwbDataBindingRenameTask.ConfigAction.class, null));
}
mtlTaskContextList.add(new MtlTaskContext(TransformTask.class));
mtlTaskContextList.add(new MtlTaskContext(PackageAwbsTask.ConfigAction.class, null));
if (appVariantContext.getAtlasExtension().getTBuildConfig().isIncremental() && (appVariantContext.getBuildType().getPatchConfig() == null || !appVariantContext.getBuildType().getPatchConfig().isCreateTPatch())) {
// mtlTaskContextList.add(new MtlTaskContext(PrepareBaseApkTask.ConfigAction.class, null));
final TaskFactory tasks = new TaskContainerAdaptor(project.getTasks());
VariantScope variantScope = appVariantContext.getVariantData().getScope();
// create the stream generated from this task
variantScope.getTransformManager().addStream(OriginalStream.builder(project, applicationVariant.getName()).addContentType(QualifiedContent.DefaultContentType.RESOURCES).addScope(QualifiedContent.Scope.PROJECT).setFolders(new Supplier<Collection<File>>() {
@Override
public Collection<File> get() {
return ImmutableList.of(new File(appVariantContext.apContext.getBaseApk() + "_"));
}
}).build());
}
final TaskFactory tasks = new TaskContainerAdaptor(project.getTasks());
VariantScope variantScope = appVariantContext.getVariantData().getScope();
mtlTaskContextList.add(new MtlTaskContext(PackageApplication.class));
if (appVariantContext.getAtlasExtension().isInstantAppEnabled()) {
mtlTaskContextList.add(new MtlTaskContext(AtlasBundleInstantApp.ConfigAction.class, null));
}
mtlTaskContextList.add(new MtlTaskContext(ApBuildTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(DiffBundleInfoTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(TPatchDiffResAPBuildTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(TPatchDiffApkBuildTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(TPatchTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext("assemble"));
new MtlTaskInjector(appVariantContext).injectTasks(mtlTaskContextList, tAndroidBuilder);
List<MtlTransformContext> mtlTransformContextList = new ArrayList<MtlTransformContext>();
if (atlasExtension.getTBuildConfig().getClassInject()) {
mtlTransformContextList.add(new MtlTransformContext(ClassInjectTransform.class, ProGuardTransform.class, DexTransform.class));
}
if (variantScope.getInstantRunBuildContext().isInInstantRunMode() && appVariantContext.getVariantConfiguration().getBuildType().isMinifyEnabled()) {
mtlTransformContextList.add(new MtlTransformContext(DelegateProguardTransform.class, ExtractJarsTransform.class, InstantRunTransform.class));
}
if (!mtlTransformContextList.isEmpty()) {
new MtlTransformInjector(appVariantContext).injectTasks(mtlTransformContextList);
}
Collection<BaseVariantOutput> baseVariantOutputDataList = appVariantContext.getVariantOutputData();
boolean multiDexEnabled = appVariantContext.getVariantData().getVariantConfiguration().isMultiDexEnabled();
if (atlasExtension.getTBuildConfig().isAtlasMultiDex() && multiDexEnabled) {
transformReplacer.replaceMultiDexListTransform();
}
transformReplacer.replaceProguardTransform();
transformReplacer.disableCache();
if (variantScope.getGlobalScope().getExtension().getDataBinding().isEnabled() && !appVariantContext.getAtlasExtension().getTBuildConfig().getAllBundlesToMdex()) {
transformReplacer.replaceDataBindingMergeArtifactsTransform();
}
for (final BaseVariantOutput vod : baseVariantOutputDataList) {
transformReplacer.replaceFixStackFramesTransform(vod);
transformReplacer.replaceDesugarTransform(vod);
transformReplacer.replaceDexArchiveBuilderTransform(vod);
transformReplacer.replaceDexExternalLibMerge(vod);
transformReplacer.replaceDexMerge(vod);
transformReplacer.replaceDexTransform(appVariantContext, vod);
transformReplacer.replaceShrinkResourcesTransform();
transformReplacer.replaceMergeJavaResourcesTransform(appVariantContext, vod);
transformReplacer.repalaceSomeInstantTransform(vod);
if (atlasExtension.getTBuildConfig().isIncremental()) {
InstantRunPatchingPolicy patchingPolicy = variantScope.getInstantRunBuildContext().getPatchingPolicy();
BaseVariantOutputImpl variantOutput = (BaseVariantOutputImpl) vod;
ApkData data = ApkDataUtils.get(variantOutput);
AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(variantScope.getFullVariantName());
//
}
}
// Boolean includeCompileClasspath =
// appVariantContext.getScope().getVariantConfiguration()
// .getJavaCompileOptions()
// .getAnnotationProcessorOptions()
// .getIncludeCompileClasspath();
// appVariantContext.getVariantData().javaCompilerTask.doFirst(task -> {
// JavaCompile compile = (JavaCompile) task;
// Set<File> mainDexFiles = new MainFilesCollection(appVariantContext.getVariantName()).getFiles();
// FileCollection mainFiles = appVariantContext.getProject().files(mainDexFiles);
// FileCollection files = appVariantContext.getScope().getArtifactFileCollection(ANNOTATION_PROCESSOR, ALL, JAR);
// FileCollection bootFiles = appVariantContext.getProject().files(appVariantContext.getScope().getGlobalScope().getAndroidBuilder().getBootClasspath(false));
// mainFiles = mainFiles.plus(bootFiles);
// FileCollection fileCollection = compile.getClasspath();
// File kotlinClasses = null;
// for (File file : fileCollection) {
// if (file.getAbsolutePath().contains("kotlin-classes")) {
// mainFiles = mainFiles.plus(appVariantContext.getProject().files(file));
// kotlinClasses = file;
// break;
// }
// }
// compile.setClasspath(mainFiles);
// if (Boolean.TRUE.equals(includeCompileClasspath)) {
// compile.getOptions().setAnnotationProcessorPath(files.plus(mainFiles));
// }
// });
appVariantContext.getVariantData().javaCompilerTask.doLast(new Action<Task>() {
@Override
public void execute(Task task) {
JavaCompile compile = (JavaCompile) task;
AtlasBuildContext.atlasMainDexHelperMap.get(appVariantContext.getVariantName()).getInputDirs().add(compile.getDestinationDir());
}
});
PackageAndroidArtifact packageAndroidArtifact = appVariantContext.getVariantData().getTaskByType(PackageAndroidArtifact.class);
if (packageAndroidArtifact != null) {
ReflectUtils.updateField(packageAndroidArtifact, "javaResourceFiles", new AbstractFileCollection() {
@Override
public String getDisplayName() {
return "java-merge-res.jar";
}
@Override
public Set<File> getFiles() {
if (AtlasBuildContext.atlasMainDexHelperMap.get(packageAndroidArtifact.getVariantName()).getMainJavaRes() == null) {
return Sets.newHashSet();
}
return Sets.newHashSet(AtlasBuildContext.atlasMainDexHelperMap.get(packageAndroidArtifact.getVariantName()).getMainJavaRes());
}
});
}
TaskCollection<ExtractTryWithResourcesSupportJar> taskCollection = appVariantContext.getProject().getTasks().withType(ExtractTryWithResourcesSupportJar.class);
for (ExtractTryWithResourcesSupportJar task : taskCollection) {
task.doLast(new Action<Task>() {
@Override
public void execute(Task task) {
ConfigurableFileCollection fileCollection = variantScope.getTryWithResourceRuntimeSupportJar();
for (File file : fileCollection.getFiles()) {
if (file.exists()) {
AtlasBuildContext.atlasMainDexHelperMap.get(variantScope.getFullVariantName()).addMainDex(new BuildAtlasEnvTask.FileIdentity("runtime-deps-try-with-resources", file, false, false));
break;
}
}
}
});
}
}
});
}
use of com.android.build.gradle.internal.scope.VariantScope in project atlas by alibaba.
the class DelegateProguardTransform method applyBundleProguardConfigration.
public void applyBundleProguardConfigration(final AppVariantContext appVariantContext) {
Set<String> blackList = appVariantContext.getAtlasExtension().getTBuildConfig().getBundleProguardConfigBlackList();
List<File> proguardFiles = new ArrayList<>();
VariantScope variantScope = appVariantContext.getScope();
for (AwbBundle awbBundle : AtlasBuildContext.androidDependencyTrees.get(variantScope.getVariantConfiguration().getFullName()).getAwbBundles()) {
for (AndroidLibrary androidDependency : awbBundle.getAllLibraryAars()) {
File proguardRules = androidDependency.getProguardRules();
String groupName = androidDependency.getResolvedCoordinates().getGroupId() + ":" + androidDependency.getResolvedCoordinates().getArtifactId();
if (blackList.contains(groupName)) {
sLogger.info("[proguard] skip proguard from " + androidDependency.getResolvedCoordinates());
continue;
}
if (proguardRules.isFile()) {
proguardFiles.add(proguardRules);
sLogger.warn("[proguard] load proguard from " + androidDependency.getResolvedCoordinates());
} else {
sLogger.info("[proguard] missing proguard from " + androidDependency.getResolvedCoordinates());
}
}
}
defaultProguardFiles.addAll(proguardFiles);
}
use of com.android.build.gradle.internal.scope.VariantScope in project atlas by alibaba.
the class DelegateProguardTransform method applyBundleInOutConfigration.
public File applyBundleInOutConfigration(final AppVariantContext appVariantContext) {
VariantScope variantScope = appVariantContext.getScope();
GlobalScope globalScope = variantScope.getGlobalScope();
File proguardOut = new File(Joiner.on(File.separatorChar).join(String.valueOf(globalScope.getBuildDir()), FD_OUTPUTS, "mapping", variantScope.getVariantConfiguration().getDirName()));
File awbInOutConfig = new File(proguardOut, "awb_inout_config.cfg");
// Add awb configuration
AtlasDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(variantScope.getVariantConfiguration().getFullName());
if (dependencyTree.getAwbBundles().size() > 0) {
BaseVariantOutput vod = (BaseVariantOutput) appVariantContext.getVariantOutputData().iterator().next();
AppVariantOutputContext appVariantOutputContext = appVariantContext.getAppVariantOutputContext(ApkDataUtils.get(vod));
File awbObfuscatedDir = new File(globalScope.getIntermediatesDir(), "/classes-proguard/" + variantScope.getVariantConfiguration().getDirName());
AwbProguardConfiguration awbProguardConfiguration = new AwbProguardConfiguration(appVariantOutputContext.getAwbTransformMap().values(), awbObfuscatedDir, appVariantOutputContext);
try {
awbProguardConfiguration.printConfigFile(awbInOutConfig);
} catch (IOException e) {
throw new GradleException("", e);
}
defaultProguardFiles.add(awbInOutConfig);
}
return awbInOutConfig;
}
use of com.android.build.gradle.internal.scope.VariantScope in project atlas by alibaba.
the class AtlasDependencyGraph method computeArtifactCollection.
public static ArtifactCollection computeArtifactCollection(VariantScope variantScope, @NonNull AtlasAndroidArtifacts.ConsumedConfigType configType, @NonNull AndroidArtifacts.ArtifactScope scope, @NonNull AtlasAndroidArtifacts.AtlasArtifactType artifactType) {
Configuration configuration;
switch(configType) {
case COMPILE_CLASSPATH:
configuration = variantScope.getVariantData().getVariantDependency().getCompileClasspath();
break;
case RUNTIME_CLASSPATH:
configuration = variantScope.getVariantData().getVariantDependency().getRuntimeClasspath();
break;
case BUNDLECOMPILE_CLASSPATH:
configuration = variantScope.getGlobalScope().getProject().getConfigurations().maybeCreate(AtlasPlugin.BUNDLE_COMPILE);
break;
case ANNOTATION_PROCESSOR:
configuration = variantScope.getVariantData().getVariantDependency().getAnnotationProcessorConfiguration();
break;
case METADATA_VALUES:
configuration = variantScope.getVariantData().getVariantDependency().getMetadataValuesConfiguration();
break;
default:
throw new RuntimeException("unknown ConfigType value");
}
Action<AttributeContainer> attributes = container -> container.attribute(ARTIFACT_TYPE, artifactType.getType());
Spec<ComponentIdentifier> filter = getComponentFilter(scope);
boolean lenientMode = Boolean.TRUE.equals(variantScope.getGlobalScope().getProjectOptions().get(BooleanOption.IDE_BUILD_MODEL_ONLY));
ArtifactCollection artifacts = configuration.getIncoming().artifactView(config -> {
config.attributes(attributes);
if (filter != null) {
config.componentFilter(filter);
}
// TODO somehow read the unresolved dependencies?
config.lenient(lenientMode);
}).getArtifacts();
if (configType == AtlasAndroidArtifacts.ConsumedConfigType.RUNTIME_CLASSPATH && variantScope.getVariantConfiguration().getType() == VariantType.FEATURE && artifactType != AtlasAndroidArtifacts.AtlasArtifactType.FEATURE_TRANSITIVE_DEPS) {
artifacts = new FilteredArtifactCollection(variantScope.getGlobalScope().getProject(), artifacts, computeArtifactCollection(variantScope, AtlasAndroidArtifacts.ConsumedConfigType.RUNTIME_CLASSPATH, scope, AtlasAndroidArtifacts.AtlasArtifactType.FEATURE_TRANSITIVE_DEPS).getArtifactFiles());
}
return artifacts;
}
Aggregations