Search in sources :

Example 21 with AndroidProject

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

the class AppResourceRepository method getResourceVisibility.

@NotNull
public ResourceVisibilityLookup getResourceVisibility(@NotNull AndroidFacet facet) {
    // TODO: b/23032391
    AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
    if (androidModel != null) {
        ResourceVisibilityLookup.Provider provider = getResourceVisibilityProvider();
        if (provider != null) {
            AndroidProject androidProject = androidModel.getAndroidProject();
            Variant variant = androidModel.getSelectedVariant();
            return provider.get(androidProject, variant);
        }
    }
    return ResourceVisibilityLookup.NONE;
}
Also used : Variant(com.android.builder.model.Variant) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) ResourceVisibilityLookup(com.android.ide.common.repository.ResourceVisibilityLookup) AndroidProject(com.android.builder.model.AndroidProject) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with AndroidProject

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

the class DependenciesModuleSetupStep method doSetUpModule.

@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull AndroidModuleModel androidModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
    AndroidProject androidProject = androidModel.getAndroidProject();
    DependencySet dependencies = myDependenciesExtractor.extractFrom(androidModel);
    for (LibraryDependency dependency : dependencies.onLibraries()) {
        updateLibraryDependency(module, ideModelsProvider, dependency, androidProject);
    }
    for (ModuleDependency dependency : dependencies.onModules()) {
        updateModuleDependency(module, ideModelsProvider, dependency, androidProject);
    }
    addExtraSdkLibrariesAsDependencies(module, ideModelsProvider, androidProject);
    Collection<SyncIssue> syncIssues = androidModel.getSyncIssues();
    if (syncIssues != null) {
        SyncIssuesReporter.getInstance().report(syncIssues, module);
    } else {
        //noinspection deprecation
        Collection<String> unresolvedDependencies = androidProject.getUnresolvedDependencies();
        UnresolvedDependenciesReporter.getInstance().report(unresolvedDependencies, module);
    }
}
Also used : ModuleDependency(com.android.tools.idea.gradle.project.sync.setup.module.dependency.ModuleDependency) LibraryDependency(com.android.tools.idea.gradle.project.sync.setup.module.dependency.LibraryDependency) SyncIssue(com.android.builder.model.SyncIssue) DependencySet(com.android.tools.idea.gradle.project.sync.setup.module.dependency.DependencySet) AndroidProject(com.android.builder.model.AndroidProject)

Example 23 with AndroidProject

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

the class JdkModuleSetupStep method setUpInAndroidStudio.

@VisibleForTesting
void setUpInAndroidStudio(@NotNull Module module, @NotNull AndroidModuleModel androidModel) {
    AndroidProject androidProject = androidModel.getAndroidProject();
    String compileTarget = androidProject.getCompileTarget();
    AndroidVersion version = AndroidTargetHash.getPlatformVersion(compileTarget);
    if (version != null && version.getFeatureLevel() >= 21) {
        Sdk jdk = myIdeSdks.getJdk();
        if (jdk != null && !myJdks.isApplicableJdk(jdk, JDK_1_7)) {
            Project project = module.getProject();
            SyncMessage msg;
            String text = "compileSdkVersion " + compileTarget + " requires compiling with JDK 7 or newer.";
            VirtualFile buildFile = getGradleBuildFile(module);
            if (buildFile != null) {
                msg = reportWrongJdkError(project, text, buildFile);
            } else {
                msg = reportWrongJdkError(project, text);
            }
            SyncMessages.getInstance(project).report(msg);
            GradleSyncState.getInstance(project).getSummary().setWrongJdkFound(true);
        }
    }
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) AndroidProject(com.android.builder.model.AndroidProject) AndroidProject(com.android.builder.model.AndroidProject) Sdk(com.intellij.openapi.projectRoots.Sdk) AndroidVersion(com.android.sdklib.AndroidVersion) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 24 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 25 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)

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