use of com.android.build.gradle.internal.api.LibVariantContext in project atlas by alibaba.
the class AtlasLibTaskManager method runTask.
@Override
public void runTask() {
new UpdatePomTask(project).updatePom();
libraryExtension.getLibraryVariants().forEach(libraryVariant -> {
LibVariantContext libVariantContext = new LibVariantContext((LibraryVariantImpl) libraryVariant, project, atlasExtension, libraryExtension);
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");
}
// if (atlasExtension.getBundleConfig().isAwbBundle()) {
// createAwoTask(libVariantContext, zipTask);
// } else {
// createDexTask(libVariantContext, zipTask);
// }
}
}
// List<TransformTask>transformTasks = TransformManager.findTransformTaskByTransformType(libVariantContext,LibraryAarJarsTransform.class);
// for (TransformTask transformTask: transformTasks){
// Transform transform = transformTask.getTransform();
// if (transform instanceof LibraryBaseTransform){
// ReflectUtils.updateField(transform,"excludeListProviders", Lists.newArrayList(new AtlasExcludeListProvider()));
// }
// }
}
});
}
use of com.android.build.gradle.internal.api.LibVariantContext 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.api.LibVariantContext in project atlas by alibaba.
the class AtlasLibTaskManager method runTask.
@Override
public void runTask() {
//不做资源的合并
if (!atlasExtension.getBundleConfig().isMergeRes()) {
new ResMerger(project).mergeRes();
}
//对maven发布失败做异常翻译, 一目了然
new PublishHooker(project).hookPublish();
libraryExtension.getLibraryVariants().forEach(new Consumer<LibraryVariant>() {
@Override
public void accept(LibraryVariant libraryVariant) {
//if ("debug".equals(libraryVariant.getBaseName())) {
// new ModuleInfoWriter(project,libraryVariant).write();
//}
LibVariantContext libVariantContext = new LibVariantContext((LibraryVariantImpl) libraryVariant, project, atlasExtension, libraryExtension);
List<Zip> zipTasks = libVariantContext.getZipTasks();
if (zipTasks.isEmpty()) {
return;
}
for (Zip zipTask : zipTasks) {
new AndroidComponetCreator(atlasExtension, project).createAndroidComponent(zipTask);
//生成 awb 和 jar
new AwbGenerator(atlasExtension).generate(zipTask);
}
}
});
libraryExtension.getLibraryVariants().forEach(new Consumer<LibraryVariant>() {
@Override
public void accept(LibraryVariant libraryVariant) {
LibVariantContext libVariantContext = new LibVariantContext((LibraryVariantImpl) libraryVariant, project, atlasExtension, libraryExtension);
List<Zip> zipTasks = libVariantContext.getZipTasks();
if (zipTasks.isEmpty()) {
return;
}
for (Zip zipTask : zipTasks) {
TBuildType tBuildType = libVariantContext.getBuildType();
if (null != tBuildType) {
try {
new AwoPropHandler().process(tBuildType, atlasExtension.getBundleConfig());
} catch (Exception e) {
throw new GradleException("process awo exception", e);
}
}
//TODO DEBUG it
if (atlasExtension.getBundleConfig().isAwoBuildEnabled() && libraryVariant.getName().equals("debug")) {
libVariantContext.setBundleTask(zipTask);
try {
libVariantContext.setAwbBundle(createAwbBundle(libVariantContext, libraryVariant.getName()));
} catch (IOException e) {
throw new GradleException("set awb bundle error");
}
if (atlasExtension.getBundleConfig().isAwbBundle()) {
createAwoTask(libVariantContext, zipTask);
} else {
createDexTask(libVariantContext, zipTask);
}
}
}
}
});
}
Aggregations