Search in sources :

Example 6 with AndroidArtifact

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

Example 7 with AndroidArtifact

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

the class AndroidRootUtil method getApkPath.

@Nullable
public static String getApkPath(@NotNull AndroidFacet facet) {
    if (facet.requiresAndroidModel()) {
        AndroidModuleModel androidModuleModel = AndroidModuleModel.get(facet);
        if (androidModuleModel != null) {
            // For Android-Gradle projects, AndroidModel is not null.
            AndroidArtifact mainArtifact = androidModuleModel.getMainArtifact();
            AndroidArtifactOutput output = getOutput(mainArtifact);
            File outputFile = output.getMainOutputFile().getOutputFile();
            return outputFile.getAbsolutePath();
        } else {
            return null;
        }
    }
    String path = facet.getProperties().APK_PATH;
    if (path.length() == 0) {
        return getOutputPackage(facet.getModule());
    }
    String moduleDirPath = getModuleDirPath(facet.getModule());
    return moduleDirPath != null ? toSystemDependentName(moduleDirPath + path) : null;
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidArtifactOutput(com.android.builder.model.AndroidArtifactOutput) AndroidArtifact(com.android.builder.model.AndroidArtifact) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AndroidArtifact (com.android.builder.model.AndroidArtifact)7 AndroidArtifactOutput (com.android.builder.model.AndroidArtifactOutput)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 Nullable (org.jetbrains.annotations.Nullable)3 NotNull (org.jetbrains.annotations.NotNull)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 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 Module (com.intellij.openapi.module.Module)1 Pair (com.intellij.openapi.util.Pair)1 PsiFile (com.intellij.psi.PsiFile)1