Search in sources :

Example 1 with SdkHandler

use of com.android.build.gradle.internal.SdkHandler 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;
                    }
                }
            }
        }
    });
}
Also used : TaskExecutionGraphListener(org.gradle.api.execution.TaskExecutionGraphListener) SdkLibData(com.android.builder.sdk.SdkLibData) TransformTask(com.android.build.gradle.internal.pipeline.TransformTask) Task(org.gradle.api.Task) JackPreDexTransform(com.android.build.gradle.tasks.JackPreDexTransform) JacocoPlugin(com.android.build.gradle.internal.coverage.JacocoPlugin) DataBindingBuilder(android.databinding.tool.DataBindingBuilder) BuildListener(org.gradle.BuildListener) BuildResult(org.gradle.BuildResult) ExtraModelInfo(com.android.build.gradle.internal.ExtraModelInfo) GradleProcessExecutor(com.android.build.gradle.internal.process.GradleProcessExecutor) LibraryCache(com.android.build.gradle.internal.LibraryCache) AndroidBuilder(com.android.builder.core.AndroidBuilder) TransformTask(com.android.build.gradle.internal.pipeline.TransformTask) Gradle(org.gradle.api.invocation.Gradle) SdkHandler(com.android.build.gradle.internal.SdkHandler) Transform(com.android.build.api.transform.Transform) DexTransform(com.android.build.gradle.internal.transforms.DexTransform) JackPreDexTransform(com.android.build.gradle.tasks.JackPreDexTransform) File(java.io.File) TaskExecutionGraph(org.gradle.api.execution.TaskExecutionGraph) DexTransform(com.android.build.gradle.internal.transforms.DexTransform) JackPreDexTransform(com.android.build.gradle.tasks.JackPreDexTransform) Settings(org.gradle.api.initialization.Settings) GradleJavaProcessExecutor(com.android.build.gradle.internal.process.GradleJavaProcessExecutor)

Aggregations

DataBindingBuilder (android.databinding.tool.DataBindingBuilder)1 Transform (com.android.build.api.transform.Transform)1 ExtraModelInfo (com.android.build.gradle.internal.ExtraModelInfo)1 LibraryCache (com.android.build.gradle.internal.LibraryCache)1 SdkHandler (com.android.build.gradle.internal.SdkHandler)1 JacocoPlugin (com.android.build.gradle.internal.coverage.JacocoPlugin)1 TransformTask (com.android.build.gradle.internal.pipeline.TransformTask)1 GradleJavaProcessExecutor (com.android.build.gradle.internal.process.GradleJavaProcessExecutor)1 GradleProcessExecutor (com.android.build.gradle.internal.process.GradleProcessExecutor)1 DexTransform (com.android.build.gradle.internal.transforms.DexTransform)1 JackPreDexTransform (com.android.build.gradle.tasks.JackPreDexTransform)1 AndroidBuilder (com.android.builder.core.AndroidBuilder)1 SdkLibData (com.android.builder.sdk.SdkLibData)1 File (java.io.File)1 BuildListener (org.gradle.BuildListener)1 BuildResult (org.gradle.BuildResult)1 Task (org.gradle.api.Task)1 TaskExecutionGraph (org.gradle.api.execution.TaskExecutionGraph)1 TaskExecutionGraphListener (org.gradle.api.execution.TaskExecutionGraphListener)1 Settings (org.gradle.api.initialization.Settings)1