Search in sources :

Example 1 with TestedTargetVariant

use of com.android.builder.model.TestedTargetVariant 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;
}
Also used : Variant(com.android.builder.model.Variant) TestedTargetVariant(com.android.builder.model.TestedTargetVariant) TestedTargetVariant(com.android.builder.model.TestedTargetVariant) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) OutputFile(com.android.build.OutputFile) File(java.io.File) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

OutputFile (com.android.build.OutputFile)1 TestedTargetVariant (com.android.builder.model.TestedTargetVariant)1 Variant (com.android.builder.model.Variant)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 Module (com.intellij.openapi.module.Module)1 File (java.io.File)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1 NotNull (org.jetbrains.annotations.NotNull)1