use of com.android.builder.model.Variant in project android by JetBrains.
the class VariantSelector method findVariantToSelect.
@Nullable
public Variant findVariantToSelect(@NotNull AndroidProject androidProject) {
Collection<Variant> variants = androidProject.getVariants();
if (variants.size() == 1) {
Variant variant = getFirstItem(variants);
assert variant != null;
return variant;
}
// trying to match something else may add more complexity for little gain.
for (Variant variant : variants) {
if ("debug".equals(variant.getName())) {
return variant;
}
}
List<Variant> sortedVariants = Lists.newArrayList(variants);
sort(sortedVariants, (o1, o2) -> o1.getName().compareTo(o2.getName()));
return sortedVariants.isEmpty() ? null : sortedVariants.get(0);
}
use of com.android.builder.model.Variant in project android by JetBrains.
the class ModuleVariantsInfoDialog method createDependentsTree.
@NotNull
private static JTree createDependentsTree(@NotNull Module module, @NotNull AndroidModuleModel androidModel) {
VariantCheckboxTreeCellRenderer renderer = new VariantCheckboxTreeCellRenderer() {
@Override
public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
if (value instanceof DefaultMutableTreeNode) {
Object data = ((DefaultMutableTreeNode) value).getUserObject();
if (data instanceof String) {
appendVariant((String) data);
} else if (data instanceof DependentTreeElement) {
DependentTreeElement dependent = (DependentTreeElement) data;
String variant = null;
if (!dependent.myVariants.isEmpty()) {
variant = Joiner.on(", ").join(dependent.myVariants);
}
appendModule(dependent.myModule, variant);
}
}
}
};
//noinspection ConstantConditions
CheckedTreeNode root = new CheckedTreeNode(null);
AndroidProject androidProject = GradleUtil.getAndroidProject(module);
assert androidProject != null;
String gradlePath = GradleUtil.getGradlePath(module);
assert gradlePath != null;
Multimap<String, DependentTreeElement> dependentsByVariant = HashMultimap.create();
ModuleManager moduleManager = ModuleManager.getInstance(module.getProject());
for (Module dependent : moduleManager.getModuleDependentModules(module)) {
AndroidProject dependentProject = GradleUtil.getAndroidProject(dependent);
if (dependentProject == null) {
continue;
}
DependentTreeElement element = new DependentTreeElement(dependent);
for (Variant variant : dependentProject.getVariants()) {
for (AndroidLibrary library : GradleUtil.getDirectLibraryDependencies(variant, androidModel)) {
if (gradlePath.equals(library.getProject())) {
element.addVariant(variant.getName());
String projectVariant = library.getProjectVariant();
if (StringUtil.isNotEmpty(projectVariant)) {
dependentsByVariant.put(projectVariant, element);
}
}
}
}
}
List<String> variantNames = Lists.newArrayList(dependentsByVariant.keySet());
Collections.sort(variantNames);
for (String variantName : variantNames) {
Collection<DependentTreeElement> dependents = dependentsByVariant.get(variantName);
if (!dependents.isEmpty()) {
List<DependentTreeElement> sortedDependents = Lists.newArrayList(dependents);
Collections.sort(sortedDependents);
DefaultMutableTreeNode variantNode = new DefaultMutableTreeNode(variantName);
for (DependentTreeElement dependent : dependents) {
variantNode.add(new DefaultMutableTreeNode(dependent));
}
root.add(variantNode);
}
}
CheckboxTree tree = new CheckboxTree(renderer, root);
tree.setRootVisible(false);
TreeUtil.expandAll(tree);
return tree;
}
use of com.android.builder.model.Variant in project android by JetBrains.
the class BuildVariantUpdater method updateSelectedVariant.
private boolean updateSelectedVariant(@NotNull AndroidFacet androidFacet, @NotNull AndroidModuleModel androidModel, @NotNull String variantToSelect, @NotNull List<AndroidFacet> affectedFacets) {
Variant selectedVariant = androidModel.getSelectedVariant();
if (variantToSelect.equals(selectedVariant.getName())) {
return false;
}
androidModel.setSelectedVariantName(variantToSelect);
androidModel.syncSelectedVariantAndTestArtifact(androidFacet);
Module module = setUpModule(androidFacet.getModule(), androidModel);
for (AndroidLibrary library : androidModel.getSelectedMainCompileDependencies().getLibraries()) {
String gradlePath = library.getProject();
if (isEmpty(gradlePath)) {
continue;
}
String projectVariant = library.getProjectVariant();
if (isNotEmpty(projectVariant)) {
ensureVariantIsSelected(module.getProject(), gradlePath, projectVariant, affectedFacets);
}
}
return true;
}
use of com.android.builder.model.Variant in project android by JetBrains.
the class AndroidTestRunConfiguration method findInstrumentationRunner.
@Nullable
public static String findInstrumentationRunner(@NotNull AndroidFacet facet) {
String runner = getRunnerFromManifest(facet);
// TODO: Resolve direct AndroidGradleModel dep (b/22596984)
AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
if (runner == null && androidModel != null) {
Variant selectedVariant = androidModel.getSelectedVariant();
String testRunner = selectedVariant.getMergedFlavor().getTestInstrumentationRunner();
if (testRunner != null) {
runner = testRunner;
}
}
return runner;
}
use of com.android.builder.model.Variant in project android by JetBrains.
the class GradleApkProvider method getTargetedApks.
/**
* Gets the list of targeted apks for the specified variant.
*
* <p>This is used for test-only modules when specifying the tested apk
* using the targetProjectPath and targetVariant properties in the build file.
*/
@NotNull
private List<ApkInfo> getTargetedApks(@NotNull Variant selectedVariant, @NotNull IDevice device) throws ApkProvisionException {
List<ApkInfo> targetedApks = Lists.newArrayList();
for (TestedTargetVariant testedVariant : getTestedTargetVariants(selectedVariant)) {
Module targetModule = ApplicationManager.getApplication().runReadAction((Computable<Module>) () -> GradleUtil.findModuleByGradlePath(myFacet.getModule().getProject(), testedVariant.getTargetProjectPath()));
// target module has to exist, otherwise we would not be able to build test apk
assert targetModule != null;
AndroidFacet targetFacet = AndroidFacet.getInstance(targetModule);
if (targetFacet == null) {
LOG.warn("Please install tested apk manually.");
continue;
}
AndroidModuleModel targetAndroidModel = AndroidModuleModel.get(targetFacet);
if (targetAndroidModel == null) {
LOG.warn("Android model for tested module is null. Sync might have failed.");
continue;
}
Variant targetVariant = targetAndroidModel.findVariantByName(testedVariant.getTargetVariant());
if (targetVariant == null) {
LOG.warn("Tested variant not found. Sync might have failed.");
continue;
}
File targetApk = getApk(targetVariant, device);
targetedApks.add(new ApkInfo(targetApk, targetVariant.getMergedFlavor().getApplicationId()));
}
return targetedApks;
}
Aggregations