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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations