Search in sources :

Example 1 with OutputFile

use of com.android.build.OutputFile 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 2 with OutputFile

use of com.android.build.OutputFile in project android by JetBrains.

the class GradleApkProvider method getApk.

@NotNull
private static File getApk(@NotNull Variant variant, @NotNull IDevice device) throws ApkProvisionException {
    AndroidArtifact mainArtifact = variant.getMainArtifact();
    List<AndroidArtifactOutput> outputs = Lists.newArrayList(mainArtifact.getOutputs());
    if (outputs.isEmpty()) {
        throw new ApkProvisionException("No outputs for the main artifact of variant: " + variant.getDisplayName());
    }
    List<String> abis = device.getAbis();
    int density = device.getDensity();
    Set<String> variantAbiFilters = mainArtifact.getAbiFilters();
    List<OutputFile> apkFiles = SplitOutputMatcher.computeBestOutput(outputs, variantAbiFilters, density, abis);
    if (apkFiles.isEmpty()) {
        String message = AndroidBundle.message("deployment.failed.splitapk.nomatch", variant.getDisplayName(), outputs.size(), density, Joiner.on(", ").join(abis));
        throw new ApkProvisionException(message);
    }
    return apkFiles.get(0).getOutputFile();
}
Also used : OutputFile(com.android.build.OutputFile) AndroidArtifactOutput(com.android.builder.model.AndroidArtifactOutput) AndroidArtifact(com.android.builder.model.AndroidArtifact) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

OutputFile (com.android.build.OutputFile)2 AndroidArtifact (com.android.builder.model.AndroidArtifact)2 AndroidArtifactOutput (com.android.builder.model.AndroidArtifactOutput)2 Nullable (com.android.annotations.Nullable)1 FilterData (com.android.build.FilterData)1 AndroidProject (com.android.builder.model.AndroidProject)1 ProductFlavorContainer (com.android.builder.model.ProductFlavorContainer)1 Variant (com.android.builder.model.Variant)1 NotNull (org.jetbrains.annotations.NotNull)1