Search in sources :

Example 36 with AndroidPlatform

use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.

the class ExportSignedPackageWizard method createAndAlignApk.

private void createAndAlignApk(final String apkPath) {
    AndroidPlatform platform = getFacet().getConfiguration().getAndroidPlatform();
    assert platform != null;
    String sdkPath = platform.getSdkData().getLocation().getPath();
    String zipAlignPath = AndroidCommonUtils.getZipAlign(sdkPath, platform.getTarget());
    File zipalign = new File(zipAlignPath);
    if (!zipalign.isFile()) {
        BuildToolInfo buildTool = platform.getTarget().getBuildToolInfo();
        if (buildTool != null) {
            zipAlignPath = buildTool.getPath(BuildToolInfo.PathId.ZIP_ALIGN);
            zipalign = new File(zipAlignPath);
        }
    }
    final boolean runZipAlign = zipalign.isFile();
    File destFile = null;
    try {
        destFile = runZipAlign ? FileUtil.createTempFile("android", ".apk") : new File(apkPath);
        createApk(destFile);
    } catch (Exception e) {
        showErrorInDispatchThread(e.getMessage());
    }
    if (destFile == null) {
        return;
    }
    if (runZipAlign) {
        File realDestFile = new File(apkPath);
        String message = AndroidCommonUtils.executeZipAlign(zipAlignPath, destFile, realDestFile);
        if (message != null) {
            showErrorInDispatchThread(message);
            return;
        }
    }
    invokeLaterIfNeeded(new Runnable() {

        @Override
        public void run() {
            String title = AndroidBundle.message("android.export.package.wizard.title");
            Project project = getProject();
            File apkFile = new File(apkPath);
            VirtualFile vApkFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(apkFile);
            if (vApkFile != null) {
                vApkFile.refresh(true, false);
            }
            if (!runZipAlign) {
                Messages.showWarningDialog(project, AndroidCommonBundle.message("android.artifact.building.cannot.find.zip.align.error"), title);
            }
            if (ShowFilePathAction.isSupported()) {
                if (Messages.showOkCancelDialog(project, AndroidBundle.message("android.export.package.success.message", apkFile.getName()), title, RevealFileAction.getActionName(), IdeBundle.message("action.close"), Messages.getInformationIcon()) == Messages.OK) {
                    ShowFilePathAction.openFile(apkFile);
                }
            } else {
                Messages.showInfoMessage(project, AndroidBundle.message("android.export.package.success.message", apkFile), title);
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AndroidProject(com.android.builder.model.AndroidProject) Project(com.intellij.openapi.project.Project) BuildToolInfo(com.android.sdklib.BuildToolInfo) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) CommitStepException(com.intellij.ide.wizard.CommitStepException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException)

Example 37 with AndroidPlatform

use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.

the class ResourceHelper method getCompletionFromTypes.

/**
   * Returns the list of all resource names that can be used as a value for one of the {@link ResourceType} in completionTypes,
   * optionally sorting/not sorting the results.
   */
@NotNull
public static List<String> getCompletionFromTypes(@NotNull AndroidFacet facet, @NotNull EnumSet<ResourceType> completionTypes, boolean sort) {
    EnumSet<ResourceType> types = Sets.newEnumSet(completionTypes, ResourceType.class);
    // Use drawables for mipmaps
    if (types.contains(ResourceType.MIPMAP)) {
        types.add(ResourceType.DRAWABLE);
    } else if (types.contains(ResourceType.DRAWABLE)) {
        types.add(ResourceType.MIPMAP);
    }
    boolean completionTypesContainsColor = types.contains(ResourceType.COLOR);
    if (types.contains(ResourceType.DRAWABLE)) {
        // The Drawable type accepts colors as value but not color state lists.
        types.add(ResourceType.COLOR);
    }
    AppResourceRepository repository = AppResourceRepository.getAppResources(facet, true);
    ResourceVisibilityLookup lookup = repository.getResourceVisibility(facet);
    AndroidPlatform androidPlatform = AndroidPlatform.getInstance(facet.getModule());
    FrameworkResources frameworkResources = null;
    if (androidPlatform != null) {
        AndroidTargetData targetData = androidPlatform.getSdkData().getTargetData(androidPlatform.getTarget());
        try {
            frameworkResources = targetData.getFrameworkResources(true);
        } catch (IOException ignore) {
        }
    }
    List<String> resources = Lists.newArrayListWithCapacity(500);
    for (ResourceType type : types) {
        // If type == ResourceType.COLOR, we want to include file resources (i.e. color state lists) only in the case where
        // color was present in completionTypes, and not if we added it because of the presence of ResourceType.DRAWABLES.
        // For any other ResourceType, we always include file resources.
        boolean includeFileResources = (type != ResourceType.COLOR) || completionTypesContainsColor;
        if (frameworkResources != null) {
            addFrameworkItems(resources, type, includeFileResources, frameworkResources);
        }
        addProjectItems(resources, type, includeFileResources, repository, lookup);
    }
    if (sort) {
        Collections.sort(resources, ResourceHelper::compareResourceReferences);
    }
    return resources;
}
Also used : FrameworkResources(com.android.ide.common.resources.FrameworkResources) ResourceType(com.android.resources.ResourceType) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) ResourceVisibilityLookup(com.android.ide.common.repository.ResourceVisibilityLookup) IOException(java.io.IOException) AndroidTargetData(org.jetbrains.android.sdk.AndroidTargetData) NotNull(org.jetbrains.annotations.NotNull)

Example 38 with AndroidPlatform

use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.

the class AttachAndroidSdkSourcesNotificationProvider method createNotificationPanel.

@Override
@Nullable
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
    if (file.getFileType() != JavaClassFileType.INSTANCE) {
        return null;
    }
    // Locate the java source of the class file, if not found, then it might come from a SDK.
    if (JavaEditorFileSwapper.findSourceFile(myProject, file) == null) {
        JdkOrderEntry jdkOrderEntry = findAndroidSdkEntryForFile(file);
        if (jdkOrderEntry == null) {
            return null;
        }
        Sdk sdk = jdkOrderEntry.getJdk();
        String sdkHome = sdk.getHomePath();
        if (sdkHome == null) {
            return null;
        }
        if (sdk.getRootProvider().getFiles(OrderRootType.SOURCES).length > 0) {
            return null;
        }
        AndroidPlatform platform = AndroidPlatform.getInstance(sdk);
        if (platform == null) {
            return null;
        }
        EditorNotificationPanel panel = new EditorNotificationPanel();
        panel.setText("Sources for '" + jdkOrderEntry.getJdkName() + "' not found.");
        panel.createActionLabel("Download", () -> {
            List<String> requested = Lists.newArrayList();
            requested.add(DetailsTypes.getSourcesPath(platform.getApiVersion()));
            ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPaths(myProject, requested);
            if (dialog != null && dialog.showAndGet()) {
                updateSdkSourceRoot(sdk);
            }
        });
        panel.createActionLabel("Refresh (if already downloaded)", () -> updateSdkSourceRoot(sdk));
        return panel;
    }
    return null;
}
Also used : EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Sdk(com.intellij.openapi.projectRoots.Sdk) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog) Nullable(org.jetbrains.annotations.Nullable)

Example 39 with AndroidPlatform

use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.

the class AddAndroidActivityPath method init.

@Override
protected void init() {
    Module module = getModule();
    assert module != null;
    AndroidFacet facet = AndroidFacet.getInstance(module);
    assert facet != null;
    AndroidPlatform platform = AndroidPlatform.getInstance(module);
    if (platform != null) {
        myState.put(KEY_BUILD_SDK, platform.getTarget().getVersion().getFeatureLevel());
    }
    AndroidModuleInfo moduleInfo = AndroidModuleInfo.get(facet);
    AndroidVersion minSdkVersion = moduleInfo.getMinSdkVersion();
    myState.put(KEY_MIN_SDK, minSdkVersion);
    myState.put(KEY_TARGET_API, moduleInfo.getTargetSdkVersion());
    myState.put(KEY_PACKAGE_NAME, getInitialPackageName(module, facet));
    myState.put(KEY_OPEN_EDITORS, true);
    if (myTemplate == null) {
        FormFactor formFactor = getFormFactor(myTargetFolder);
        myState.put(FormFactorUtils.getMinApiLevelKey(formFactor), minSdkVersion.getApiLevel());
        myState.put(FormFactorUtils.getBuildApiLevelKey(formFactor), moduleInfo.getTargetSdkVersion().getApiLevel());
        ActivityGalleryStep galleryStep = new ActivityGalleryStep(formFactor, false, KEY_SELECTED_TEMPLATE, module, myParentDisposable);
        addStep(galleryStep);
    } else {
        TemplateMetadata templateMetadata = TemplateManager.getInstance().getTemplateMetadata(myTemplate);
        assert templateMetadata != null;
        myState.put(KEY_SELECTED_TEMPLATE, new TemplateEntry(myTemplate, templateMetadata));
    }
    SourceProvider[] sourceProviders = getSourceProviders(module, myTargetFolder);
    boolean isInstantAppModule = facet.getProjectType() == PROJECT_TYPE_ATOM;
    myState.put(IS_INSTANT_APP_KEY, isInstantAppModule);
    myParameterStep = new TemplateParameterStep2(getFormFactor(myTargetFolder), ImmutableMap.of(), myParentDisposable, KEY_PACKAGE_NAME, sourceProviders, CUSTOMIZE_ACTIVITY_TITLE);
    myAssetStudioStep = new IconStep(KEY_SELECTED_TEMPLATE, KEY_SOURCE_PROVIDER, myParentDisposable);
    addStep(myParameterStep);
    addStep(myAssetStudioStep);
}
Also used : IdeaSourceProvider(org.jetbrains.android.facet.IdeaSourceProvider) SourceProvider(com.android.builder.model.SourceProvider) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) AndroidVersion(com.android.sdklib.AndroidVersion) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) AndroidModuleInfo(com.android.tools.idea.model.AndroidModuleInfo) Module(com.intellij.openapi.module.Module) TemplateMetadata(com.android.tools.idea.templates.TemplateMetadata)

Example 40 with AndroidPlatform

use of org.jetbrains.android.sdk.AndroidPlatform 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)

Aggregations

AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)46 Module (com.intellij.openapi.module.Module)16 IAndroidTarget (com.android.sdklib.IAndroidTarget)13 Nullable (org.jetbrains.annotations.Nullable)11 Project (com.intellij.openapi.project.Project)10 Sdk (com.intellij.openapi.projectRoots.Sdk)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)10 File (java.io.File)9 IOException (java.io.IOException)9 AndroidVersion (com.android.sdklib.AndroidVersion)8 NotNull (org.jetbrains.annotations.NotNull)6 AndroidTargetData (org.jetbrains.android.sdk.AndroidTargetData)5 LayoutLibrary (com.android.ide.common.rendering.LayoutLibrary)3 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)3 RenderingException (com.android.tools.idea.layoutlib.RenderingException)3 AndroidModuleInfo (com.android.tools.idea.model.AndroidModuleInfo)3 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)3 SourceProvider (com.android.builder.model.SourceProvider)2 IDevice (com.android.ddmlib.IDevice)2