Search in sources :

Example 1 with CompileOptions

use of com.android.build.gradle.internal.CompileOptions in project atlas by alibaba.

the class AwoJavaCompileConfigAction method execute.

/**
     * Awb的编译,暂不支持instantRun
     *
     * @param javacTask
     */
@Override
public void execute(JavaCompile javacTask) {
    //        libVariantContext.setJavacTask(javacTask);
    javacTask.setSource(libVariantContext.getSourceOutputDir());
    ConventionMappingHelper.map(javacTask, "classpath", new Callable<FileCollection>() {

        @Override
        public FileCollection call() {
            FileCollection classpath = scope.getJavaClasspath();
            return classpath;
        }
    });
    javacTask.setDestinationDir(libVariantContext.getJavaCDir());
    javacTask.setDependencyCacheDir(new File(scope.getGlobalScope().getIntermediatesDir(), "/awb-dependency-cache/" + scope.getVariantConfiguration().getFullName() + "/" + awbBundle.getName()));
    CompileOptions compileOptions = scope.getGlobalScope().getExtension().getCompileOptions();
    AbstractCompilesUtil.configureLanguageLevel(javacTask, compileOptions, scope.getGlobalScope().getExtension().getCompileSdkVersion(), false);
    javacTask.getOptions().setEncoding(compileOptions.getEncoding());
    javacTask.getOptions().setBootClasspath(Joiner.on(File.pathSeparator).join(scope.getGlobalScope().getAndroidBuilder().getBootClasspathAsStrings(false)));
    GlobalScope globalScope = scope.getGlobalScope();
    Project project = globalScope.getProject();
    boolean incremental;
    if (compileOptions.getIncremental() != null) {
        incremental = compileOptions.getIncremental();
    } else {
        // if (globalScope.getExtension().getDataBinding().isEnabled()
        // || project.getPlugins().hasPlugin("com.neenbedankt.android-apt")
        // || project.getPlugins().hasPlugin("me.tatarka.retrolambda")) {
        // incremental = false;
        // } else {
        // For now, default to false, irrespective of Instant Run.
        incremental = false;
    // }
    }
    if (AndroidGradleOptions.isJavaCompileIncrementalPropertySet(project)) {
        scope.getGlobalScope().getAndroidBuilder().getErrorReporter().handleSyncError(null, SyncIssue.TYPE_GENERIC, String.format("The %s property has been replaced by a DSL property. Please add the " + "following to your build.gradle instead:\n" + "android {\n" + "  compileOptions.incremental = false\n" + "}", AndroidGradleOptions.PROPERTY_INCREMENTAL_JAVA_COMPILE));
    }
    if (incremental) {
        LOG.info("Using incremental javac compilation.");
    } else {
        LOG.info("Not using incremental javac compilation.");
    }
    javacTask.getOptions().setIncremental(incremental);
}
Also used : GlobalScope(com.android.build.gradle.internal.scope.GlobalScope) Project(org.gradle.api.Project) CompileOptions(com.android.build.gradle.internal.CompileOptions) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File)

Example 2 with CompileOptions

use of com.android.build.gradle.internal.CompileOptions in project atlas by alibaba.

the class AwbJavaCompileConfigAction method execute.

/**
     * Awb的编译,暂不支持instantRun
     *
     * @param javacTask
     */
@Override
public void execute(JavaCompile javacTask) {
    appVariantOutputContext.getAwbJavacTasks().put(awbBundle.getName(), javacTask);
    ProcessAwbAndroidResources processAwbAndroidResources = appVariantOutputContext.getAwbAndroidResourcesMap().get(awbBundle.getName());
    assert null != processAwbAndroidResources;
    javacTask.source(processAwbAndroidResources.getSourceOutputDir());
    if (scope.getGlobalScope().getExtension().getDataBinding().isEnabled()) {
        javacTask.source(appVariantOutputContext.getVariantContext().getAwbClassOutputForDataBinding(awbBundle));
    }
    ConventionMappingHelper.map(javacTask, "classpath", new Callable<FileCollection>() {

        @Override
        public FileCollection call() {
            FileCollection classpath = scope.getVariantScope().getJavaClasspath();
            Set<File> dependencies = new HashSet<File>();
            dependencies.addAll(classpath.getFiles());
            //增加awb的依赖
            dependencies.addAll(awbBundle.getLibraryJars());
            FileCollection allClassPatch = appVariantOutputContext.getVariantContext().getProject().files(dependencies);
            return allClassPatch;
        }
    });
    javacTask.setDestinationDir(appVariantOutputContext.getJAwbavaOutputDir(awbBundle));
    javacTask.setDependencyCacheDir(appVariantOutputContext.getAwbJavaDependencyCache(awbBundle));
    CompileOptions compileOptions = scope.getGlobalScope().getExtension().getCompileOptions();
    AbstractCompilesUtil.configureLanguageLevel(javacTask, compileOptions, scope.getGlobalScope().getExtension().getCompileSdkVersion(), false);
    javacTask.getOptions().setEncoding(compileOptions.getEncoding());
    javacTask.getOptions().setBootClasspath(Joiner.on(File.pathSeparator).join(scope.getGlobalScope().getAndroidBuilder().getBootClasspathAsStrings(false)));
    GlobalScope globalScope = scope.getGlobalScope();
    Project project = globalScope.getProject();
    boolean incremental;
    if (compileOptions.getIncremental() != null) {
        incremental = compileOptions.getIncremental();
    } else {
        // if (globalScope.getExtension().getDataBinding().isEnabled()
        // || project.getPlugins().hasPlugin("com.neenbedankt.android-apt")
        // || project.getPlugins().hasPlugin("me.tatarka.retrolambda")) {
        // incremental = false;
        // } else {
        // For now, default to false, irrespective of Instant Run.
        incremental = false;
    // }
    }
    if (AndroidGradleOptions.isJavaCompileIncrementalPropertySet(project)) {
        scope.getGlobalScope().getAndroidBuilder().getErrorReporter().handleSyncError(null, SyncIssue.TYPE_GENERIC, String.format("The %s property has been replaced by a DSL property. Please add the " + "following to your build.gradle instead:\n" + "android {\n" + "  compileOptions.incremental = false\n" + "}", AndroidGradleOptions.PROPERTY_INCREMENTAL_JAVA_COMPILE));
    }
    if (incremental) {
        LOG.info("Using incremental javac compilation.");
    } else {
        LOG.info("Not using incremental javac compilation.");
    }
    javacTask.getOptions().setIncremental(incremental);
}
Also used : GlobalScope(com.android.build.gradle.internal.scope.GlobalScope) Project(org.gradle.api.Project) Set(java.util.Set) HashSet(java.util.HashSet) CompileOptions(com.android.build.gradle.internal.CompileOptions) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File)

Aggregations

CompileOptions (com.android.build.gradle.internal.CompileOptions)2 GlobalScope (com.android.build.gradle.internal.scope.GlobalScope)2 File (java.io.File)2 Project (org.gradle.api.Project)2 FileCollection (org.gradle.api.file.FileCollection)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1