com.android.builder.core.BuilderConstants Java Examples

The following examples show how to use com.android.builder.core.BuilderConstants. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProductFlavor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds a new field to the generated BuildConfig class.
 * <p>
 * The field is generated as:
 * <p>
 * <type> <name> = <value>;
 * <p>
 * This means each of these must have valid Java content. If the type is a String, then the
 * value should include quotes.
 *
 * @param type  the type of the field
 * @param name  the name of the field
 * @param value the value of the field
 */
public void buildConfigField(
        @NonNull String type,
        @NonNull String name,
        @NonNull String value) {
    ClassField alreadyPresent = getBuildConfigFields().get(name);
    if (alreadyPresent != null) {
        String flavorName = getName();
        if (BuilderConstants.MAIN.equals(flavorName)) {
            logger.info(
                    "DefaultConfig: buildConfigField '{}' value is being replaced: {} -> {}",
                    name, alreadyPresent.getValue(), value);
        } else {
            logger.info(
                    "ProductFlavor({}): buildConfigField '{}' "
                            + "value is being replaced: {} -> {}",
                    flavorName, name, alreadyPresent.getValue(), value);
        }
    }
    addBuildConfigField(AndroidBuilder.createClassField(type, name, value));
}
 
Example #2
Source File: ProductFlavor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds a new generated resource.
 * <p>
 * <p>This is equivalent to specifying a resource in res/values.
 * <p>
 * <p>See <a href="http://developer.android.com/guide/topics/resources/available-resources.html">Resource Types</a>.
 *
 * @param type  the type of the resource
 * @param name  the name of the resource
 * @param value the value of the resource
 */
public void resValue(
        @NonNull String type,
        @NonNull String name,
        @NonNull String value) {
    ClassField alreadyPresent = getResValues().get(name);
    if (alreadyPresent != null) {
        String flavorName = getName();
        if (BuilderConstants.MAIN.equals(flavorName)) {
            logger.info(
                    "DefaultConfig: resValue '{}' value is being replaced: {} -> {}",
                    name, alreadyPresent.getValue(), value);
        } else {
            logger.info(
                    "ProductFlavor({}): resValue '{}' value is being replaced: {} -> {}",
                    flavorName, name, alreadyPresent.getValue(), value);
        }
    }
    addResValue(AndroidBuilder.createClassField(type, name, value));
}
 
Example #3
Source File: ProductFlavorData.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
ProductFlavorData(
        @NonNull T productFlavor,
        @NonNull DefaultAndroidSourceSet sourceSet,
        @NonNull Project project) {
    super(sourceSet, project);

    this.productFlavor = productFlavor;

    if (!BuilderConstants.MAIN.equals(sourceSet.getName())) {
        String sourceSetName = StringHelper.capitalize(sourceSet.getName());
        assembleTask = project.getTasks().create("assemble" + sourceSetName);
        assembleTask.setDescription("Assembles all " + sourceSetName + " builds.");
        assembleTask.setGroup(BasePlugin.BUILD_GROUP);
    } else {
        assembleTask = null;
    }
}
 
Example #4
Source File: AndroidConfigAdaptor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private void applyProjectSourceSet() {
    for (FunctionalSourceSet source : getSources()) {
        String name = source.getName();
        AndroidSourceSet androidSource = name.equals(BuilderConstants.MAIN) ?
                sourceSetsContainer.maybeCreate(getDefaultConfig().getName()) :
                sourceSetsContainer.maybeCreate(name);

        convertSourceFile(androidSource.getManifest(), source, "manifest");
        convertSourceSet(androidSource.getResources(), source, "resource");
        convertSourceSet(androidSource.getJava(), source, "java");
        convertSourceSet(androidSource.getRes(), source, "res");
        convertSourceSet(androidSource.getAssets(), source, "assets");
        convertSourceSet(androidSource.getAidl(), source, "aidl");
        convertSourceSet(androidSource.getJni(), source, "jni");
        convertSourceSet(androidSource.getJniLibs(), source, "jniLibs");
    }
}
 
Example #5
Source File: AndroidComponentModelPlugin.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Defaults
public void createDefaultBuildTypes(
        @Path("android.buildTypes") ModelMap<BuildType> buildTypes) {
    buildTypes.create(BuilderConstants.DEBUG, new Action<BuildType>() {
        @Override
        public void execute(BuildType buildType) {
            buildType.setDebuggable(true);
        }
    });
    buildTypes.create(BuilderConstants.RELEASE);
}
 
Example #6
Source File: SigningConfig.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a SigningConfig with a given name.
 *
 * @param name the name of the signingConfig.
 */
public SigningConfig(@NonNull String name) {
    super(name);

    if (BuilderConstants.DEBUG.equals(name)) {
        try {
            initDebug();
        } catch (AndroidLocation.AndroidLocationException e) {
            throw new BuildException("Failed to get default debug keystore location", e);
        }
    }
}
 
Example #7
Source File: AndroidConfigHelper.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public static void configure(
        @NonNull AndroidConfig model,
        @NonNull Instantiator instantiator) {
    model.setDefaultPublishConfig(BuilderConstants.RELEASE);
    model.setPublishNonDefault(false);
    model.setGeneratePureSplits(false);
    model.setPreProcessingOptions(instantiator.newInstance(PreprocessingOptions.class));
    model.setAaptOptions(instantiator.newInstance(AaptOptions.class));
    model.setDexOptions(instantiator.newInstance(DexOptions.class));
    model.setLintOptions(instantiator.newInstance(LintOptions.class));
    model.setCompileOptions(instantiator.newInstance(CompileOptions.class));
    model.setPackagingOptions(instantiator.newInstance(PackagingOptions.class));
    model.setSplits(instantiator.newInstance(Splits.class, instantiator));
    model.setLibraryRequests(Lists.<LibraryRequest>newArrayList());
}
 
Example #8
Source File: MergeResources.java    From javafxmobile-plugin with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
        public void execute(MergeResources mergeResourcesTask) {
            final Project project = androidExtension.getProject();

            mergeResourcesTask.setMinSdk(Integer.parseInt(androidExtension.getMinSdkVersion()));
            mergeResourcesTask.buildToolInfo = () -> BuildToolInfo.fromStandardDirectoryLayout(
                    androidExtension.getBuildToolsRevision(), androidExtension.getBuildToolsDir());

            mergeResourcesTask.aaptGeneration = AaptGeneration.AAPT_V1;
            mergeResourcesTask.setAndroidBuilder(androidExtension.getAndroidBuilder());
            mergeResourcesTask.fileCache = androidExtension.getBuildCache();
            mergeResourcesTask.setVariantName("jfx");
            mergeResourcesTask.setIncrementalFolder(androidExtension.getIncrementalDirectory(getName()));
            // Libraries use this task twice, once for compilation (with dependencies),
            // where blame is useful, and once for packaging where it is not.
            if (includeDependencies) {
                mergeResourcesTask.setBlameLogFolder(androidExtension.getResourceBlameLogDirectory());
            }
            mergeResourcesTask.processResources = processResources;
            mergeResourcesTask.crunchPng = true;

            final boolean validateEnabled = true;

            mergeResourcesTask.setValidateEnabled(validateEnabled);

//            if (includeDependencies) {
//                mergeResourcesTask.libraries = scope.getArtifactCollection(
//                        RUNTIME_CLASSPATH, ALL, ANDROID_RES);
//            }

            mergeResourcesTask.resSetSupplier =
                    () -> {
                        ResourceSet mainResourceSet = new ResourceSet(BuilderConstants.MAIN, null, null, validateEnabled);
                        mainResourceSet.addSource(project.file(androidExtension.getResDirectory()));
                        return Collections.singletonList(mainResourceSet);
                    };
            mergeResourcesTask.sourceFolderInputs =
                    TaskInputHelper.bypassFileSupplier(
                            () -> Collections.singletonList(project.file(androidExtension.getResDirectory())));
            mergeResourcesTask.renderscriptResOutputDir = project.files(androidExtension.getRenderscriptResOutputDirectory());
            mergeResourcesTask.generatedResOutputDir = project.files(androidExtension.getGeneratedResOutputDirectory());

            mergeResourcesTask.setOutputDir(outputLocation);
            mergeResourcesTask.setGeneratedPngsOutputDir(androidExtension.getGeneratedPngsOutputDirectory());
        }
 
Example #9
Source File: BaseExtension.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
BaseExtension(
        @NonNull final ProjectInternal project,
        @NonNull Instantiator instantiator,
        @NonNull AndroidBuilder androidBuilder,
        @NonNull SdkHandler sdkHandler,
        @NonNull NamedDomainObjectContainer<BuildType> buildTypes,
        @NonNull NamedDomainObjectContainer<ProductFlavor> productFlavors,
        @NonNull NamedDomainObjectContainer<SigningConfig> signingConfigs,
        @NonNull ExtraModelInfo extraModelInfo,
        final boolean isLibrary) {
    this.androidBuilder = androidBuilder;
    this.sdkHandler = sdkHandler;
    this.buildTypes = buildTypes;
    //noinspection unchecked
    this.productFlavors = (NamedDomainObjectContainer) productFlavors;
    this.signingConfigs = signingConfigs;
    this.extraModelInfo = extraModelInfo;
    this.project = project;

    logger = Logging.getLogger(this.getClass());

    defaultConfig = instantiator.newInstance(ProductFlavor.class, BuilderConstants.MAIN,
            project, instantiator, project.getLogger());

    aaptOptions = instantiator.newInstance(AaptOptions.class);
    dexOptions = instantiator.newInstance(DexOptions.class);
    lintOptions = instantiator.newInstance(LintOptions.class);
    compileOptions = instantiator.newInstance(CompileOptions.class);
    packagingOptions = instantiator.newInstance(PackagingOptions.class);
    preprocessingOptions = instantiator.newInstance(PreprocessingOptions.class);
    splits = instantiator.newInstance(Splits.class, instantiator);

    sourceSetsContainer = project.container(AndroidSourceSet.class,
            new AndroidSourceSetFactory(instantiator, project, isLibrary));

    sourceSetsContainer.whenObjectAdded(new Action<AndroidSourceSet>() {
        @Override
        public void execute(AndroidSourceSet sourceSet) {
            ConfigurationContainer configurations = project.getConfigurations();

            createConfiguration(
                    configurations,
                    sourceSet.getCompileConfigurationName(),
                    "Classpath for compiling the " + sourceSet.getName() + " sources.");

            String packageConfigDescription;
            if (isLibrary) {
                packageConfigDescription
                        = "Classpath only used when publishing '" + sourceSet.getName() + "'.";
            } else {
                packageConfigDescription
                        = "Classpath packaged with the compiled '" + sourceSet.getName() + "' classes.";
            }
            createConfiguration(
                    configurations,
                    sourceSet.getPackageConfigurationName(),
                    packageConfigDescription);

            createConfiguration(
                    configurations,
                    sourceSet.getProvidedConfigurationName(),
                    "Classpath for only compiling the " + sourceSet.getName() + " sources.");

            createConfiguration(
                    configurations,
                    sourceSet.getWearAppConfigurationName(),
                    "Link to a wear app to embed for object '" + sourceSet.getName() + "'.");

            sourceSet.setRoot(String.format("src/%s", sourceSet.getName()));
        }
    });

    sourceSetsContainer.create(defaultConfig.getName());
}
 
Example #10
Source File: ProductFlavorAdaptor.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
@Override
public String getName() {
    return productFlavor.getName().equals("defaultConfig") ? BuilderConstants.MAIN : productFlavor.getName();
}