Search in sources :

Example 1 with Variant

use of com.android.builder.model.Variant in project kotlin by JetBrains.

the class Project method getResourceVisibility.

/**
     * Returns a shared {@link ResourceVisibilityLookup}
     *
     * @return a shared provider for looking up resource visibility
     */
@NonNull
public ResourceVisibilityLookup getResourceVisibility() {
    if (mResourceVisibility == null) {
        if (isGradleProject()) {
            AndroidProject project = getGradleProjectModel();
            Variant variant = getCurrentVariant();
            if (project != null && variant != null) {
                mResourceVisibility = mClient.getResourceVisibilityProvider().get(project, variant);
            } else if (getGradleLibraryModel() != null) {
                try {
                    mResourceVisibility = mClient.getResourceVisibilityProvider().get(getGradleLibraryModel());
                } catch (Exception ignore) {
                // Handle talking to older Gradle plugins (where we don't
                // have access to the model version to check up front
                }
            }
        }
        if (mResourceVisibility == null) {
            mResourceVisibility = ResourceVisibilityLookup.NONE;
        }
    }
    return mResourceVisibility;
}
Also used : Variant(com.android.builder.model.Variant) AndroidProject(com.android.builder.model.AndroidProject) CircularDependencyException(com.android.tools.klint.client.api.CircularDependencyException) IOException(java.io.IOException) NonNull(com.android.annotations.NonNull)

Example 2 with Variant

use of com.android.builder.model.Variant in project kotlin by JetBrains.

the class Project method getApplicableDensities.

/**
     * Returns the set of applicable densities for this project. If null, there are no density
     * restrictions and all densities apply.
     *
     * @return the list of specific densities that apply in this project, or null if all densities
     * apply
     */
@Nullable
public List<String> getApplicableDensities() {
    if (mCachedApplicableDensities == null) {
        // ...then we should only enforce hdpi densities, not all these others!
        if (isGradleProject() && getGradleProjectModel() != null && getCurrentVariant() != null) {
            Set<String> relevantDensities = Sets.newHashSet();
            Variant variant = getCurrentVariant();
            List<String> variantFlavors = variant.getProductFlavors();
            AndroidProject gradleProjectModel = getGradleProjectModel();
            addResConfigsFromFlavor(relevantDensities, null, getGradleProjectModel().getDefaultConfig());
            for (ProductFlavorContainer container : gradleProjectModel.getProductFlavors()) {
                addResConfigsFromFlavor(relevantDensities, variantFlavors, container);
            }
            // Are there any splits that specify densities?
            if (relevantDensities.isEmpty()) {
                AndroidArtifact mainArtifact = variant.getMainArtifact();
                Collection<AndroidArtifactOutput> outputs = mainArtifact.getOutputs();
                for (AndroidArtifactOutput output : outputs) {
                    for (OutputFile file : output.getOutputs()) {
                        final String DENSITY_NAME = OutputFile.FilterType.DENSITY.name();
                        if (file.getFilterTypes().contains(DENSITY_NAME)) {
                            for (FilterData data : file.getFilters()) {
                                if (DENSITY_NAME.equals(data.getFilterType())) {
                                    relevantDensities.add(data.getIdentifier());
                                }
                            }
                        }
                    }
                }
            }
            if (!relevantDensities.isEmpty()) {
                mCachedApplicableDensities = Lists.newArrayListWithExpectedSize(10);
                for (String density : relevantDensities) {
                    String folder = ResourceFolderType.DRAWABLE.getName() + '-' + density;
                    mCachedApplicableDensities.add(folder);
                }
                Collections.sort(mCachedApplicableDensities);
            } else {
                mCachedApplicableDensities = Collections.emptyList();
            }
        } else {
            mCachedApplicableDensities = Collections.emptyList();
        }
    }
    return mCachedApplicableDensities.isEmpty() ? null : mCachedApplicableDensities;
}
Also used : Variant(com.android.builder.model.Variant) OutputFile(com.android.build.OutputFile) ProductFlavorContainer(com.android.builder.model.ProductFlavorContainer) FilterData(com.android.build.FilterData) AndroidProject(com.android.builder.model.AndroidProject) AndroidArtifactOutput(com.android.builder.model.AndroidArtifactOutput) AndroidArtifact(com.android.builder.model.AndroidArtifact) Nullable(com.android.annotations.Nullable)

Example 3 with Variant

use of com.android.builder.model.Variant in project android by JetBrains.

the class DynamicResourceValueRepository method getMap.

@Override
@NonNull
protected Map<ResourceType, ListMultimap<String, ResourceItem>> getMap() {
    if (mItems.isEmpty()) {
        // TODO: b/23032391
        AndroidModuleModel androidModel = AndroidModuleModel.get(myFacet);
        if (androidModel == null) {
            return mItems;
        }
        Variant selectedVariant = androidModel.getSelectedVariant();
        // Reverse overlay order because when processing lower order ones, we ignore keys already processed
        BuildTypeContainer buildType = androidModel.findBuildType(selectedVariant.getBuildType());
        if (buildType != null) {
            addValues(buildType.getBuildType().getResValues());
        }
        // flavors and default config:
        addValues(selectedVariant.getMergedFlavor().getResValues());
    }
    return mItems;
}
Also used : Variant(com.android.builder.model.Variant) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) BuildTypeContainer(com.android.builder.model.BuildTypeContainer) NonNull(com.android.annotations.NonNull)

Example 4 with Variant

use of com.android.builder.model.Variant in project android by JetBrains.

the class ProjectSubset method addResultAndPopulateProject.

/**
   * Adds the module in the given search results to the IDE. If the search result indicates the variant where the file is, this method
   * will select such variant in the Android model.
   *
   * @param result          the search result.
   * @param projectInfo     information about the project.
   * @param selectedModules all the modules to be included in the project.
   * @param file            the file to include in the project.
   */
private void addResultAndPopulateProject(@NotNull ModuleSearchResult result, @NotNull DataNode<ProjectData> projectInfo, @NotNull List<DataNode<ModuleData>> selectedModules, @NotNull File file) {
    DataNode<ModuleData> moduleNode = result.moduleNode;
    String moduleName = getNameOf(moduleNode);
    String text;
    if (result.selected) {
        String tmp = String.format("File '%1$s' is already in module '%2$s'", file.getName(), moduleName);
        SourceFileContainerInfo containerInfo = result.containerInfo;
        if (containerInfo != null) {
            containerInfo.updateSelectedVariantIn(moduleNode);
            Variant variant = containerInfo.variant;
            if (variant != null) {
                tmp += String.format(", variant '%1$s'", variant.getName());
            }
        }
        text = tmp;
    } else {
        text = String.format("Module '%1$s' was added to the project.", moduleName);
        SourceFileContainerInfo containerInfo = result.containerInfo;
        if (containerInfo != null) {
            containerInfo.updateSelectedVariantIn(moduleNode);
        }
        selectedModules.add(moduleNode);
        setSelection(selectedModules);
    }
    invokeLaterIfNeeded(() -> {
        AndroidGradleNotification notification = AndroidGradleNotification.getInstance(myProject);
        notification.showBalloon(MODULE_LOOKUP_MESSAGE_TITLE, text, INFORMATION);
    });
    populate(myProject, projectInfo, selectedModules, DEFAULT_REQUEST);
}
Also used : Variant(com.android.builder.model.Variant) SourceFileContainerInfo(com.android.tools.idea.gradle.project.model.AndroidModuleModel.SourceFileContainerInfo) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) AndroidGradleNotification(com.android.tools.idea.gradle.project.AndroidGradleNotification)

Example 5 with Variant

use of com.android.builder.model.Variant in project android by JetBrains.

the class ExportSignedPackageWizard method getAssembleTasks.

@VisibleForTesting
public static List<String> getAssembleTasks(String gradleProjectPath, AndroidProject androidProject, String buildType, List<String> flavors) {
    Map<String, Variant> variantsByFlavor = Maps.newHashMapWithExpectedSize(flavors.size());
    for (Variant v : androidProject.getVariants()) {
        if (!v.getBuildType().equals(buildType)) {
            continue;
        }
        variantsByFlavor.put(getMergedFlavorName(v), v);
    }
    if (flavors.isEmpty()) {
        // if there are no flavors defined, then the default merged flavor name is empty..
        Variant v = variantsByFlavor.get("");
        if (v != null) {
            String taskName = v.getMainArtifact().getAssembleTaskName();
            return Collections.singletonList(GradleBuildInvoker.createBuildTask(gradleProjectPath, taskName));
        } else {
            LOG.error("Unable to find default variant");
            return Collections.emptyList();
        }
    }
    List<String> assembleTasks = Lists.newArrayListWithExpectedSize(flavors.size());
    for (String flavor : flavors) {
        Variant v = variantsByFlavor.get(flavor);
        if (v != null) {
            String taskName = v.getMainArtifact().getAssembleTaskName();
            assembleTasks.add(GradleBuildInvoker.createBuildTask(gradleProjectPath, taskName));
        }
    }
    return assembleTasks;
}
Also used : Variant(com.android.builder.model.Variant) VisibleForTesting(com.android.annotations.VisibleForTesting)

Aggregations

Variant (com.android.builder.model.Variant)24 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)8 File (java.io.File)7 AndroidProject (com.android.builder.model.AndroidProject)6 AndroidLibrary (com.android.builder.model.AndroidLibrary)5 Module (com.intellij.openapi.module.Module)5 NotNull (org.jetbrains.annotations.NotNull)5 AndroidArtifact (com.android.builder.model.AndroidArtifact)4 OutputFile (com.android.build.OutputFile)3 AndroidArtifactOutput (com.android.builder.model.AndroidArtifactOutput)3 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 Nullable (org.jetbrains.annotations.Nullable)3 NonNull (com.android.annotations.NonNull)2 TestedTargetVariant (com.android.builder.model.TestedTargetVariant)2 GradleVersion (com.android.ide.common.repository.GradleVersion)2 VariantCheckboxTreeCellRenderer (com.android.tools.idea.gradle.variant.ui.VariantCheckboxTreeCellRenderer)2 ModuleManager (com.intellij.openapi.module.ModuleManager)2 CheckboxTree (com.intellij.ui.CheckboxTree)2 CheckedTreeNode (com.intellij.ui.CheckedTreeNode)2 IOException (java.io.IOException)2