Search in sources :

Example 81 with AndroidModuleModel

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

the class ApplicationRunParameters method onModuleChanged.

public void onModuleChanged() {
    Module currentModule = myModuleSelector.getModule();
    if (currentModule == null) {
        return;
    }
    // Lock and hide subset of UI when attached to an instantApp
    AndroidModuleModel model = AndroidModuleModel.get(currentModule);
    boolean isInstantApp = false;
    if (model != null && model.getProjectType() == PROJECT_TYPE_INSTANTAPP) {
        myLaunchOptionCombo.setSelectedItem(LAUNCH_DEEP_LINK);
        myDeployOptionCombo.setSelectedItem(InstallOption.DEFAULT_APK);
        isInstantApp = true;
    }
    myDeployOptionCombo.setEnabled(!isInstantApp);
    myCustomArtifactLabeledComponent.setEnabled(!isInstantApp);
    myLaunchOptionCombo.setEnabled(!isInstantApp);
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module)

Example 82 with AndroidModuleModel

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

the class NewVectorAssetAction method createWizard.

@Nullable
@Override
protected ModelWizard createWizard(@NotNull AndroidFacet facet) {
    Module module = facet.getModule();
    Project project = module.getProject();
    AndroidModuleModel androidModel = AndroidModuleModel.get(module);
    if (androidModel != null) {
        AndroidVersion minSdkVersion = androidModel.getMinSdkVersion();
        String version = androidModel.getAndroidProject().getModelVersion();
        GradleVersion revision = GradleVersion.parse(version);
        if (revision.compareIgnoringQualifiers(VECTOR_ASSET_GENERATION_REVISION) < 0 && (minSdkVersion == null || minSdkVersion.getApiLevel() < VECTOR_DRAWABLE_API_LEVEL)) {
            Messages.showErrorDialog(project, ERROR_MESSAGE, ERROR_TITLE);
            return null;
        }
    }
    ModelWizard.Builder wizardBuilder = new ModelWizard.Builder();
    wizardBuilder.addStep(new NewVectorAssetStep(new GenerateVectorIconModel(facet), facet));
    return wizardBuilder.build();
}
Also used : Project(com.intellij.openapi.project.Project) NewVectorAssetStep(com.android.tools.idea.npw.assetstudio.wizard.NewVectorAssetStep) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) GenerateVectorIconModel(com.android.tools.idea.npw.assetstudio.wizard.GenerateVectorIconModel) Module(com.intellij.openapi.module.Module) AndroidVersion(com.android.sdklib.AndroidVersion) GradleVersion(com.android.ide.common.repository.GradleVersion) ModelWizard(com.android.tools.idea.wizard.model.ModelWizard) Nullable(org.jetbrains.annotations.Nullable)

Example 83 with AndroidModuleModel

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

the class ConflictSet method findConflicts.

@NotNull
public static ConflictSet findConflicts(@NotNull Project project) {
    Map<String, Conflict> selectionConflicts = Maps.newHashMap();
    Map<String, Conflict> structureConflicts = Maps.newHashMap();
    ModuleManager moduleManager = ModuleManager.getInstance(project);
    for (Module module : moduleManager.getModules()) {
        AndroidModuleModel currentAndroidModel = AndroidModuleModel.get(module);
        if (currentAndroidModel == null || currentAndroidModel.getProjectType() == PROJECT_TYPE_APP) {
            continue;
        }
        String gradlePath = GradleUtil.getGradlePath(module);
        if (gradlePath == null) {
            continue;
        }
        String selectedVariant = currentAndroidModel.getSelectedVariant().getName();
        for (Module dependent : ModuleUtilCore.getAllDependentModules(module)) {
            AndroidModuleModel dependentAndroidModel = AndroidModuleModel.get(dependent);
            if (dependentAndroidModel == null) {
                continue;
            }
            String expectedVariant = getExpectedVariant(dependentAndroidModel, gradlePath);
            if (StringUtil.isEmpty(expectedVariant)) {
                continue;
            }
            addConflict(structureConflicts, module, selectedVariant, dependent, expectedVariant);
            if (!selectedVariant.equals(expectedVariant)) {
                addConflict(selectionConflicts, module, selectedVariant, dependent, expectedVariant);
            }
        }
    }
    // Structural conflicts are the ones that have more than one group of modules depending on different variants of another module.
    List<Conflict> filteredStructureConflicts = Lists.newArrayList();
    for (Conflict conflict : structureConflicts.values()) {
        if (conflict.getVariants().size() > 1) {
            filteredStructureConflicts.add(conflict);
        }
    }
    return new ConflictSet(project, selectionConflicts.values(), filteredStructureConflicts);
}
Also used : ConflictResolution.solveSelectionConflict(com.android.tools.idea.gradle.variant.conflict.ConflictResolution.solveSelectionConflict) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 84 with AndroidModuleModel

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

the class Projects method storePluginVersionsPerModule.

public static void storePluginVersionsPerModule(@NotNull Project project) {
    Map<String, GradleVersion> pluginVersionsPerModule = Maps.newHashMap();
    for (Module module : ModuleManager.getInstance(project).getModules()) {
        AndroidModuleModel model = AndroidModuleModel.get(module);
        if (model != null) {
            GradleFacet facet = GradleFacet.getInstance(module);
            if (facet != null) {
                GradleVersion modelVersion = model.getModelVersion();
                if (modelVersion != null) {
                    pluginVersionsPerModule.put(facet.getConfiguration().GRADLE_PROJECT_PATH, modelVersion);
                }
            }
        }
    }
    project.putUserData(PLUGIN_VERSIONS_BY_MODULE, pluginVersionsPerModule);
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) GradleFacet(com.android.tools.idea.gradle.project.facet.gradle.GradleFacet) GradleVersion(com.android.ide.common.repository.GradleVersion) Module(com.intellij.openapi.module.Module)

Example 85 with AndroidModuleModel

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

the class BuildVariantUpdater method doUpdate.

@Nullable
private Module doUpdate(@NotNull Project project, @NotNull String moduleName, @NotNull String variant, @NotNull List<AndroidFacet> affectedAndroidFacets, @NotNull List<NdkFacet> affectedNativeAndroidFacets) {
    Module moduleToUpdate = findModule(project, moduleName);
    if (moduleToUpdate == null) {
        logAndShowUpdateFailure(variant, String.format("Cannot find module '%1$s'.", moduleName));
        return null;
    }
    AndroidFacet androidFacet = AndroidFacet.getInstance(moduleToUpdate);
    NdkFacet ndkFacet = NdkFacet.getInstance(moduleToUpdate);
    if (androidFacet == null && ndkFacet == null) {
        String msg = String.format("Cannot find 'Android' or 'Native-Android-Gradle' facets in module '%1$s'.", moduleToUpdate.getName());
        logAndShowUpdateFailure(variant, msg);
    }
    if (ndkFacet != null) {
        NdkModuleModel ndkModuleModel = getNativeAndroidModel(ndkFacet, variant);
        if (ndkModuleModel == null || !updateSelectedVariant(ndkFacet, ndkModuleModel, variant)) {
            return null;
        }
        affectedNativeAndroidFacets.add(ndkFacet);
    }
    if (androidFacet != null) {
        AndroidModuleModel androidModel = getAndroidModel(androidFacet, variant);
        if (androidModel == null || !updateSelectedVariant(androidFacet, androidModel, variant, affectedAndroidFacets)) {
            return null;
        }
        affectedAndroidFacets.add(androidFacet);
    }
    return moduleToUpdate;
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) NdkFacet(com.android.tools.idea.gradle.project.facet.ndk.NdkFacet) Module(com.intellij.openapi.module.Module) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Nullable(org.jetbrains.annotations.Nullable)

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