Search in sources :

Example 91 with AndroidModuleModel

use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.

the class LaunchCompatibilityCheckerImpl method create.

public static LaunchCompatibilityChecker create(@NotNull AndroidFacet facet) {
    AndroidVersion minSdkVersion = AndroidModuleInfo.get(facet).getRuntimeMinSdkVersion();
    AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
    if (platform == null) {
        throw new IllegalStateException("Android platform not set for module: " + facet.getModule().getName());
    }
    // Currently, we only look at whether the device supports the watch feature.
    // We may not want to search the device for every possible feature, but only a small subset of important
    // features, starting with hardware type watch.
    EnumSet<IDevice.HardwareFeature> requiredHardwareFeatures;
    if (LaunchUtils.isWatchFeatureRequired(facet)) {
        requiredHardwareFeatures = EnumSet.of(IDevice.HardwareFeature.WATCH);
    } else {
        requiredHardwareFeatures = EnumSet.noneOf(IDevice.HardwareFeature.class);
    }
    Set<String> supportedAbis = facet.getAndroidModel() instanceof AndroidModuleModel ? ((AndroidModuleModel) facet.getAndroidModel()).getSelectedVariant().getMainArtifact().getAbiFilters() : null;
    return new LaunchCompatibilityCheckerImpl(minSdkVersion, platform.getTarget(), requiredHardwareFeatures, supportedAbis);
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) AndroidVersion(com.android.sdklib.AndroidVersion)

Example 92 with AndroidModuleModel

use of com.android.tools.idea.gradle.project.model.AndroidModuleModel 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)

Example 93 with AndroidModuleModel

use of com.android.tools.idea.gradle.project.model.AndroidModuleModel 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)

Example 94 with AndroidModuleModel

use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.

the class AndroidJunitPatcher method handleJavaResources.

/**
   * Puts folders with merged java resources for the selected variant of every module on the classpath.
   *
   * <p>The problem we're solving here is that CompilerModuleExtension supports only one directory for "compiler output". When IJ compiles
   * Java projects, it copies resources to the output classes dir. This is something our Gradle plugin doesn't do, so we need to add the
   * resource directories to the classpath here.
   *
   * <p>We need to do this for every project dependency as well, since we're using classes and resources directories of these directly.
   *
   * @see <a href="http://b.android.com/172409">Bug 172409</a>
   */
private static void handleJavaResources(@NotNull Module module, @NotNull AndroidModuleModel androidModel, @NotNull PathsList classPath) {
    CompilerManager compilerManager = CompilerManager.getInstance(module.getProject());
    CompileScope scope = compilerManager.createModulesCompileScope(new Module[] { module }, true, true);
    // The only test resources we want to use, are the ones from the module where the test is. They should go first, before main resources.
    JavaArtifact testArtifact = androidModel.getUnitTestArtifactInSelectedVariant();
    if (testArtifact != null) {
        try {
            classPath.add(testArtifact.getJavaResourcesFolder());
        } catch (UnsupportedMethodException ignored) {
        // Java resources were not present in older versions of the gradle plugin.
        }
    }
    FileRootSearchScope excludeScope = null;
    TestArtifactSearchScopes testScopes = TestArtifactSearchScopes.get(module);
    if (testScopes != null) {
        excludeScope = testScopes.getUnitTestExcludeScope();
    }
    for (Module affectedModule : scope.getAffectedModules()) {
        AndroidFacet facet = AndroidFacet.getInstance(affectedModule);
        if (facet != null) {
            AndroidModuleModel affectedAndroidModel = AndroidModuleModel.get(facet);
            if (affectedAndroidModel != null) {
                try {
                    File resourceFolder = affectedAndroidModel.getMainArtifact().getJavaResourcesFolder();
                    if (excludeScope != null && excludeScope.accept(resourceFolder)) {
                        continue;
                    }
                    classPath.add(resourceFolder);
                } catch (UnsupportedMethodException ignored) {
                // Java resources were not present in older versions of the gradle plugin.
                }
            }
        }
    }
}
Also used : CompileScope(com.intellij.openapi.compiler.CompileScope) JavaArtifact(com.android.builder.model.JavaArtifact) UnsupportedMethodException(org.gradle.tooling.model.UnsupportedMethodException) CompilerManager(com.intellij.openapi.compiler.CompilerManager) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) File(java.io.File) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 95 with AndroidModuleModel

use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.

the class ExcludedRoots method addModuleIfNecessary.

private void addModuleIfNecessary(@NotNull Module module) {
    AndroidModuleModel androidModel = AndroidModuleModel.get(module);
    if (androidModel != null) {
        BaseArtifact unitTestArtifact = androidModel.getUnitTestArtifactInSelectedVariant();
        BaseArtifact androidTestArtifact = androidModel.getAndroidTestArtifactInSelectedVariant();
        BaseArtifact excludeArtifact = myAndroidTest ? unitTestArtifact : androidTestArtifact;
        BaseArtifact includeArtifact = myAndroidTest ? androidTestArtifact : unitTestArtifact;
        if (excludeArtifact != null) {
            processFolders(excludeArtifact, androidModel, myExcludedRoots::add);
        }
        if (includeArtifact != null) {
            processFolders(includeArtifact, androidModel, myExcludedRoots::remove);
        }
    }
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel)

Aggregations

AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)117 Module (com.intellij.openapi.module.Module)54 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)26 File (java.io.File)24 NotNull (org.jetbrains.annotations.NotNull)21 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 Nullable (org.jetbrains.annotations.Nullable)18 AndroidProject (com.android.builder.model.AndroidProject)12 GradleVersion (com.android.ide.common.repository.GradleVersion)11 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)10 Project (com.intellij.openapi.project.Project)9 Variant (com.android.builder.model.Variant)8 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)7 AndroidLibrary (com.android.builder.model.AndroidLibrary)5 PsiFile (com.intellij.psi.PsiFile)5 AndroidArtifact (com.android.builder.model.AndroidArtifact)4 AndroidArtifactOutput (com.android.builder.model.AndroidArtifactOutput)4 NativeAndroidProject (com.android.builder.model.NativeAndroidProject)4 ModuleNodeBuilder (com.android.tools.idea.gradle.AndroidModelView.ModuleNodeBuilder)4 AndroidVersion (com.android.sdklib.AndroidVersion)3