Search in sources :

Example 1 with LibVariantContext

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()));
        // }
        // }
        }
    });
}
Also used : Zip(org.gradle.api.tasks.bundling.Zip) JarExtractTask(com.taobao.android.builder.tasks.library.JarExtractTask) UpdatePomTask(com.taobao.android.builder.tasks.library.publish.UpdatePomTask) LibVariantContext(com.android.build.gradle.internal.api.LibVariantContext) IOException(java.io.IOException) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) AwoPropHandler(com.taobao.android.builder.tools.ideaplugin.AwoPropHandler) BaseVariantOutput(com.android.build.gradle.api.BaseVariantOutput) AwbGenerator(com.taobao.android.builder.tasks.library.AwbGenerator) GradleException(org.gradle.api.GradleException) LibraryVariantOutput(com.android.build.gradle.api.LibraryVariantOutput) TBuildType(com.taobao.android.builder.extension.TBuildType)

Example 2 with LibVariantContext

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");
                    }
                }
            }
        }
    });
}
Also used : Zip(org.gradle.api.tasks.bundling.Zip) FeatureVariantContext(com.android.build.gradle.internal.api.FeatureVariantContext) JarExtractTask(com.taobao.android.builder.tasks.library.JarExtractTask) LibVariantContext(com.android.build.gradle.internal.api.LibVariantContext) IOException(java.io.IOException) FilteredArtifactCollection(com.android.build.gradle.internal.dependency.FilteredArtifactCollection) TaskContainerAdaptor(com.android.build.gradle.internal.TaskContainerAdaptor) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) AwoPropHandler(com.taobao.android.builder.tools.ideaplugin.AwoPropHandler) Field(java.lang.reflect.Field) BaseVariantOutput(com.android.build.gradle.api.BaseVariantOutput) AwbGenerator(com.taobao.android.builder.tasks.library.AwbGenerator) ArtifactCollection(org.gradle.api.artifacts.ArtifactCollection) FilteredArtifactCollection(com.android.build.gradle.internal.dependency.FilteredArtifactCollection) GradleException(org.gradle.api.GradleException) LibraryVariantOutput(com.android.build.gradle.api.LibraryVariantOutput) TransformTask(com.android.build.gradle.internal.pipeline.TransformTask) Collection(java.util.Collection) ArtifactCollection(org.gradle.api.artifacts.ArtifactCollection) FilteredArtifactCollection(com.android.build.gradle.internal.dependency.FilteredArtifactCollection) FileCollection(org.gradle.api.file.FileCollection) TransformStream(com.android.build.gradle.internal.pipeline.TransformStream) TBuildType(com.taobao.android.builder.extension.TBuildType)

Example 3 with LibVariantContext

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);
                    }
                }
            }
        }
    });
}
Also used : Zip(org.gradle.api.tasks.bundling.Zip) ResMerger(com.taobao.android.builder.tasks.library.ResMerger) PublishHooker(com.taobao.android.builder.tasks.library.PublishHooker) LibVariantContext(com.android.build.gradle.internal.api.LibVariantContext) IOException(java.io.IOException) AndroidComponetCreator(com.taobao.android.builder.tasks.library.AndroidComponetCreator) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) AwoPropHandler(com.taobao.android.builder.tools.ideaplugin.AwoPropHandler) AwbGenerator(com.taobao.android.builder.tasks.library.AwbGenerator) LibraryVariant(com.android.build.gradle.api.LibraryVariant) GradleException(org.gradle.api.GradleException) ArrayList(java.util.ArrayList) List(java.util.List) LibraryVariantImpl(com.android.build.gradle.internal.api.LibraryVariantImpl) TBuildType(com.taobao.android.builder.extension.TBuildType)

Aggregations

LibVariantContext (com.android.build.gradle.internal.api.LibVariantContext)3 TBuildType (com.taobao.android.builder.extension.TBuildType)3 AwbGenerator (com.taobao.android.builder.tasks.library.AwbGenerator)3 AwoPropHandler (com.taobao.android.builder.tools.ideaplugin.AwoPropHandler)3 IOException (java.io.IOException)3 GradleException (org.gradle.api.GradleException)3 Zip (org.gradle.api.tasks.bundling.Zip)3 BaseVariantOutput (com.android.build.gradle.api.BaseVariantOutput)2 LibraryVariantOutput (com.android.build.gradle.api.LibraryVariantOutput)2 JarExtractTask (com.taobao.android.builder.tasks.library.JarExtractTask)2 LibraryVariant (com.android.build.gradle.api.LibraryVariant)1 TaskContainerAdaptor (com.android.build.gradle.internal.TaskContainerAdaptor)1 FeatureVariantContext (com.android.build.gradle.internal.api.FeatureVariantContext)1 LibraryVariantImpl (com.android.build.gradle.internal.api.LibraryVariantImpl)1 FilteredArtifactCollection (com.android.build.gradle.internal.dependency.FilteredArtifactCollection)1 TransformStream (com.android.build.gradle.internal.pipeline.TransformStream)1 TransformTask (com.android.build.gradle.internal.pipeline.TransformTask)1 AndroidComponetCreator (com.taobao.android.builder.tasks.library.AndroidComponetCreator)1 PublishHooker (com.taobao.android.builder.tasks.library.PublishHooker)1 ResMerger (com.taobao.android.builder.tasks.library.ResMerger)1