Search in sources :

Example 1 with AndroidArtifactOutput

use of com.android.builder.model.AndroidArtifactOutput 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 AndroidArtifactOutput

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

the class GradleApkProvider method getApks.

@Override
@NotNull
public Collection<ApkInfo> getApks(@NotNull IDevice device) throws ApkProvisionException {
    AndroidModuleModel androidModel = AndroidModuleModel.get(myFacet);
    if (androidModel == null) {
        LOG.warn("Android model is null. Sync might have failed");
        return Collections.emptyList();
    }
    Variant selectedVariant = androidModel.getSelectedVariant();
    List<ApkInfo> apkList = Lists.newArrayList();
    // install apk (note that variant.getOutputFile() will point to a .aar in the case of a library)
    int projectType = androidModel.getProjectType();
    if (projectType == PROJECT_TYPE_APP || projectType == PROJECT_TYPE_INSTANTAPP) {
        File apk = getApk(selectedVariant, device);
        apkList.add(new ApkInfo(apk, myApplicationIdProvider.getPackageName()));
    }
    if (myTest) {
        AndroidArtifact testArtifactInfo = androidModel.getAndroidTestArtifactInSelectedVariant();
        if (testArtifactInfo != null) {
            AndroidArtifactOutput output = GradleUtil.getOutput(testArtifactInfo);
            File testApk = output.getMainOutputFile().getOutputFile();
            String testPackageName = myApplicationIdProvider.getTestPackageName();
            // Cannot be null if initialized.
            assert testPackageName != null;
            apkList.add(new ApkInfo(testApk, testPackageName));
        }
        if (androidModel.getFeatures().isTestedTargetVariantsSupported()) {
            apkList.addAll(0, getTargetedApks(selectedVariant, device));
        }
    }
    return apkList;
}
Also used : Variant(com.android.builder.model.Variant) TestedTargetVariant(com.android.builder.model.TestedTargetVariant) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidArtifactOutput(com.android.builder.model.AndroidArtifactOutput) AndroidArtifact(com.android.builder.model.AndroidArtifact) OutputFile(com.android.build.OutputFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with AndroidArtifactOutput

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

the class AnalyzeApkAction method getLastSelectedApk.

@Nullable
private static VirtualFile getLastSelectedApk(Project project) {
    String lastApkPath = PropertiesComponent.getInstance(project).getValue(LAST_APK_PATH);
    if (lastApkPath != null) {
        File f = new File(lastApkPath);
        if (f.exists()) {
            return VfsUtil.findFileByIoFile(f, true);
        }
    }
    // see if we can find an apk generated by gradle if this is the first time
    for (Module module : ModuleManager.getInstance(project).getModules()) {
        AndroidModuleModel model = AndroidModuleModel.get(module);
        if (model == null) {
            continue;
        }
        if (model.getProjectType() != PROJECT_TYPE_APP) {
            continue;
        }
        AndroidArtifact mainArtifact = model.getSelectedVariant().getMainArtifact();
        for (AndroidArtifactOutput output : mainArtifact.getOutputs()) {
            File outputFile = output.getMainOutputFile().getOutputFile();
            if (outputFile.exists()) {
                return VfsUtil.findFileByIoFile(outputFile, true);
            }
        }
    }
    return null;
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidArtifactOutput(com.android.builder.model.AndroidArtifactOutput) Module(com.intellij.openapi.module.Module) AndroidArtifact(com.android.builder.model.AndroidArtifact) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with AndroidArtifactOutput

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

the class AndroidGradleClassJarProvider method getCompilerOutputRoot.

@Nullable
private static VirtualFile getCompilerOutputRoot(@NotNull AndroidModuleModel model) {
    Variant variant = model.getSelectedVariant();
    String variantName = variant.getName();
    AndroidArtifact mainArtifactInfo = model.getMainArtifact();
    File classesFolder = mainArtifactInfo.getClassesFolder();
    //noinspection ConstantConditions
    if (classesFolder == null) {
        // For getOutput()
        @SuppressWarnings("deprecation") AndroidArtifactOutput output = GradleUtil.getOutput(mainArtifactInfo);
        File file = output.getMainOutputFile().getOutputFile();
        File buildFolder = file.getParentFile().getParentFile();
        // See AndroidContentRoot
        classesFolder = new File(buildFolder, "classes");
    }
    File outFolder = new File(classesFolder, // Change variant name variant-release into variant/release directories
    variantName.replace('-', File.separatorChar));
    if (outFolder.exists()) {
        return VfsUtil.findFileByIoFile(outFolder, true);
    }
    return null;
}
Also used : Variant(com.android.builder.model.Variant) AndroidArtifactOutput(com.android.builder.model.AndroidArtifactOutput) AndroidArtifact(com.android.builder.model.AndroidArtifact) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with AndroidArtifactOutput

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

the class GradleApkProvider method validate.

@NotNull
@Override
public List<ValidationError> validate() {
    AndroidModuleModel androidModuleModel = AndroidModuleModel.get(myFacet);
    // This is a Gradle project, there must be an AndroidGradleModel.
    assert androidModuleModel != null;
    if (androidModuleModel.getMainArtifact().isSigned()) {
        return ImmutableList.of();
    }
    AndroidArtifactOutput output = GradleUtil.getOutput(androidModuleModel.getMainArtifact());
    final String message = AndroidBundle.message("run.error.apk.not.signed", output.getMainOutputFile().getOutputFile().getName(), androidModuleModel.getSelectedVariant().getDisplayName());
    Runnable quickFix = new Runnable() {

        @Override
        public void run() {
            Module module = myFacet.getModule();
            ProjectSettingsService service = ProjectSettingsService.getInstance(module.getProject());
            if (service instanceof AndroidProjectSettingsService) {
                ((AndroidProjectSettingsService) service).openSigningConfiguration(module);
            } else {
                service.openModuleSettings(module);
            }
        }
    };
    return ImmutableList.of(ValidationError.fatal(message, quickFix));
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidProjectSettingsService(com.android.tools.idea.gradle.structure.editors.AndroidProjectSettingsService) ProjectSettingsService(com.intellij.openapi.roots.ui.configuration.ProjectSettingsService) AndroidProjectSettingsService(com.android.tools.idea.gradle.structure.editors.AndroidProjectSettingsService) AndroidArtifactOutput(com.android.builder.model.AndroidArtifactOutput) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AndroidArtifactOutput (com.android.builder.model.AndroidArtifactOutput)7 AndroidArtifact (com.android.builder.model.AndroidArtifact)6 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)4 File (java.io.File)4 OutputFile (com.android.build.OutputFile)3 Variant (com.android.builder.model.Variant)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 Module (com.intellij.openapi.module.Module)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 TestedTargetVariant (com.android.builder.model.TestedTargetVariant)1 AndroidProjectSettingsService (com.android.tools.idea.gradle.structure.editors.AndroidProjectSettingsService)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 ProjectSettingsService (com.intellij.openapi.roots.ui.configuration.ProjectSettingsService)1 PsiFile (com.intellij.psi.PsiFile)1