Search in sources :

Example 26 with AndroidProject

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

the class SdkModuleSetupStep method doSetUpModule.

@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull AndroidModuleModel androidModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
    File androidSdkHomePath = IdeSdks.getInstance().getAndroidSdkPath();
    // Android SDK may be not configured in IntelliJ
    if (androidSdkHomePath == null) {
        assert !IdeInfo.getInstance().isAndroidStudio();
        logAndroidSdkHomeNotFound();
        return;
    }
    ModifiableRootModel moduleModel = ideModelsProvider.getModifiableRootModel(module);
    LanguageLevel languageLevel = androidModel.getJavaLanguageLevel();
    if (languageLevel != null) {
        moduleModel.getModuleExtension(LanguageLevelModuleExtensionImpl.class).setLanguageLevel(languageLevel);
    }
    AndroidProject androidProject = androidModel.getAndroidProject();
    String compileTarget = androidProject.getCompileTarget();
    Sdk sdk = myAndroidSdks.findSuitableAndroidSdk(compileTarget);
    if (sdk == null) {
        sdk = myAndroidSdks.tryToCreate(androidSdkHomePath, compileTarget);
        if (sdk == null) {
            // If SDK was not created, this might be an add-on.
            sdk = findMatchingSdkForAddon(androidProject);
        }
    }
    if (sdk == null) {
        showPlatformNotFoundError(module, compileTarget);
        return;
    }
    moduleModel.setSdk(sdk);
    String sdkPath = sdk.getHomePath();
    if (sdkPath == null) {
        sdkPath = "<path not set>";
    }
    getLog().info(String.format("Set Android SDK '%1$s' (%2$s) to module '%3$s'", sdk.getName(), sdkPath, module.getName()));
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) LanguageLevelModuleExtensionImpl(com.intellij.openapi.roots.LanguageLevelModuleExtensionImpl) LanguageLevel(com.intellij.pom.java.LanguageLevel) AndroidProject(com.android.builder.model.AndroidProject) Sdk(com.intellij.openapi.projectRoots.Sdk) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File)

Example 27 with AndroidProject

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

the class AndroidGradleProjectResolver method createModule.

@Override
@NotNull
public DataNode<ModuleData> createModule(@NotNull IdeaModule gradleModule, @NotNull DataNode<ProjectData> projectDataNode) {
    AndroidProject androidProject = resolverCtx.getExtraProject(gradleModule, AndroidProject.class);
    if (androidProject != null && !isSupportedVersion(androidProject)) {
        AndroidStudioEvent.Builder event = AndroidStudioEvent.newBuilder();
        // @formatter:off
        event.setCategory(GRADLE_SYNC).setKind(GRADLE_SYNC_FAILURE).setGradleSyncFailure(UNSUPPORTED_ANDROID_MODEL_VERSION).setGradleVersion(androidProject.getModelVersion());
        // @formatter:on
        UsageTracker.getInstance().log(event);
        String msg = getUnsupportedModelVersionErrorMsg(getModelVersion(androidProject));
        throw new IllegalStateException(msg);
    }
    if (isAndroidGradleProject()) {
        return doCreateModule(gradleModule, projectDataNode);
    } else {
        return nextResolver.createModule(gradleModule, projectDataNode);
    }
}
Also used : AndroidProject(com.android.builder.model.AndroidProject) NativeAndroidProject(com.android.builder.model.NativeAndroidProject) AndroidStudioEvent(com.google.wireless.android.sdk.stats.AndroidStudioEvent) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with AndroidProject

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

the class ModuleVariantsInfoDialog method createDependentsTree.

@NotNull
private static JTree createDependentsTree(@NotNull Module module, @NotNull AndroidModuleModel androidModel) {
    VariantCheckboxTreeCellRenderer renderer = new VariantCheckboxTreeCellRenderer() {

        @Override
        public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            if (value instanceof DefaultMutableTreeNode) {
                Object data = ((DefaultMutableTreeNode) value).getUserObject();
                if (data instanceof String) {
                    appendVariant((String) data);
                } else if (data instanceof DependentTreeElement) {
                    DependentTreeElement dependent = (DependentTreeElement) data;
                    String variant = null;
                    if (!dependent.myVariants.isEmpty()) {
                        variant = Joiner.on(", ").join(dependent.myVariants);
                    }
                    appendModule(dependent.myModule, variant);
                }
            }
        }
    };
    //noinspection ConstantConditions
    CheckedTreeNode root = new CheckedTreeNode(null);
    AndroidProject androidProject = GradleUtil.getAndroidProject(module);
    assert androidProject != null;
    String gradlePath = GradleUtil.getGradlePath(module);
    assert gradlePath != null;
    Multimap<String, DependentTreeElement> dependentsByVariant = HashMultimap.create();
    ModuleManager moduleManager = ModuleManager.getInstance(module.getProject());
    for (Module dependent : moduleManager.getModuleDependentModules(module)) {
        AndroidProject dependentProject = GradleUtil.getAndroidProject(dependent);
        if (dependentProject == null) {
            continue;
        }
        DependentTreeElement element = new DependentTreeElement(dependent);
        for (Variant variant : dependentProject.getVariants()) {
            for (AndroidLibrary library : GradleUtil.getDirectLibraryDependencies(variant, androidModel)) {
                if (gradlePath.equals(library.getProject())) {
                    element.addVariant(variant.getName());
                    String projectVariant = library.getProjectVariant();
                    if (StringUtil.isNotEmpty(projectVariant)) {
                        dependentsByVariant.put(projectVariant, element);
                    }
                }
            }
        }
    }
    List<String> variantNames = Lists.newArrayList(dependentsByVariant.keySet());
    Collections.sort(variantNames);
    for (String variantName : variantNames) {
        Collection<DependentTreeElement> dependents = dependentsByVariant.get(variantName);
        if (!dependents.isEmpty()) {
            List<DependentTreeElement> sortedDependents = Lists.newArrayList(dependents);
            Collections.sort(sortedDependents);
            DefaultMutableTreeNode variantNode = new DefaultMutableTreeNode(variantName);
            for (DependentTreeElement dependent : dependents) {
                variantNode.add(new DefaultMutableTreeNode(dependent));
            }
            root.add(variantNode);
        }
    }
    CheckboxTree tree = new CheckboxTree(renderer, root);
    tree.setRootVisible(false);
    TreeUtil.expandAll(tree);
    return tree;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CheckboxTree(com.intellij.ui.CheckboxTree) CheckedTreeNode(com.intellij.ui.CheckedTreeNode) AndroidProject(com.android.builder.model.AndroidProject) ModuleManager(com.intellij.openapi.module.ModuleManager) Variant(com.android.builder.model.Variant) AndroidLibrary(com.android.builder.model.AndroidLibrary) Module(com.intellij.openapi.module.Module) VariantCheckboxTreeCellRenderer(com.android.tools.idea.gradle.variant.ui.VariantCheckboxTreeCellRenderer) NotNull(org.jetbrains.annotations.NotNull)

Example 29 with AndroidProject

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

the class ExportSignedPackageTest method ignore_testNoFlavors.

// ignored: http://b.android.com/226579
public void ignore_testNoFlavors() {
    AndroidProject androidProject = getAndroidProject("no_flavors");
    assertNotNull(androidProject);
    // debug and release
    assertEquals(2, androidProject.getVariants().size());
    List<String> assembleTasks = ExportSignedPackageWizard.getAssembleTasks("", androidProject, "release", Collections.<String>emptyList());
    assertEquals(1, assembleTasks.size());
    assertEquals(":assembleRelease", assembleTasks.get(0));
}
Also used : AndroidProject(com.android.builder.model.AndroidProject)

Example 30 with AndroidProject

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

the class ExportSignedPackageTest method getAndroidProject.

/**
   * Returns the {@link com.android.builder.model.AndroidProject} given the gradle project root.
   * Note that this works only single module projects (only one build.gradle)
   */
@Nullable
private static AndroidProject getAndroidProject(String projectPath) {
    File androidPlugin = new File(AndroidTestBase.getAndroidPluginHome());
    File projectDir = new File(androidPlugin, BASE_PATH + projectPath);
    GradleConnector connector = GradleConnector.newConnector();
    connector.forProjectDirectory(projectDir);
    connector.useDistribution(new DistributionLocator().getDistributionFor(GradleVersion.version("2.2.1")));
    AndroidProject model = null;
    ProjectConnection connection = connector.connect();
    try {
        model = connection.getModel(AndroidProject.class);
    } finally {
        connection.close();
    }
    return model;
}
Also used : DistributionLocator(org.gradle.util.DistributionLocator) ProjectConnection(org.gradle.tooling.ProjectConnection) AndroidProject(com.android.builder.model.AndroidProject) File(java.io.File) GradleConnector(org.gradle.tooling.GradleConnector) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AndroidProject (com.android.builder.model.AndroidProject)35 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)12 NativeAndroidProject (com.android.builder.model.NativeAndroidProject)7 File (java.io.File)7 Variant (com.android.builder.model.Variant)6 Module (com.intellij.openapi.module.Module)6 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)6 NotNull (org.jetbrains.annotations.NotNull)6 ModuleNodeBuilder (com.android.tools.idea.gradle.AndroidModelView.ModuleNodeBuilder)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 NonNull (com.android.annotations.NonNull)3 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)3 Project (com.intellij.openapi.project.Project)3 IOException (java.io.IOException)3 AndroidLibrary (com.android.builder.model.AndroidLibrary)2 LintOptions (com.android.builder.model.LintOptions)2 ProductFlavorContainer (com.android.builder.model.ProductFlavorContainer)2 LibraryDependency (com.android.tools.idea.gradle.project.sync.setup.module.dependency.LibraryDependency)2 GradleUtil.getAndroidProject (com.android.tools.idea.gradle.util.GradleUtil.getAndroidProject)2 GradleUtil.getNativeAndroidProject (com.android.tools.idea.gradle.util.GradleUtil.getNativeAndroidProject)2