Search in sources :

Example 31 with AndroidPlatform

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

the class AndroidApplicationArtifactProperties method onBuildFinished.

@Override
public void onBuildFinished(@NotNull Artifact artifact, @NotNull CompileContext context) {
    if (!(artifact.getArtifactType() instanceof AndroidApplicationArtifactType)) {
        return;
    }
    if (mySigningMode != AndroidArtifactSigningMode.RELEASE_SIGNED && mySigningMode != AndroidArtifactSigningMode.DEBUG_WITH_CUSTOM_CERTIFICATE) {
        return;
    }
    final AndroidFacet facet = AndroidArtifactUtil.getPackagedFacet(context.getProject(), artifact);
    if (facet == null) {
        return;
    }
    final String artifactName = artifact.getName();
    final String messagePrefix = "[Artifact '" + artifactName + "'] ";
    final Module module = facet.getModule();
    final AndroidPlatform platform = AndroidPlatform.getInstance(module);
    if (platform == null) {
        context.addMessage(CompilerMessageCategory.ERROR, messagePrefix + AndroidBundle.message("android.compilation.error.specify.platform", module.getName()), null, -1, -1);
        return;
    }
    final String sdkLocation = platform.getSdkData().getPath();
    final String artifactFilePath = artifact.getOutputFilePath();
    final String keyStorePath = myKeyStoreUrl != null ? VfsUtilCore.urlToPath(myKeyStoreUrl) : "";
    final String keyStorePassword = myKeyStorePassword != null && myKeyStorePassword.length() > 0 ? getPlainKeystorePassword() : null;
    final String keyPassword = myKeyPassword != null && myKeyPassword.length() > 0 ? getPlainKeyPassword() : null;
    try {
        final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidCommonUtils.buildArtifact(artifactName, messagePrefix, sdkLocation, platform.getTarget(), artifactFilePath, keyStorePath, myKeyAlias, keyStorePassword, keyPassword);
        AndroidCompileUtil.addMessages(context, AndroidCompileUtil.toCompilerMessageCategoryKeys(messages), null);
    } catch (GeneralSecurityException e) {
        AndroidCompileUtil.reportException(context, messagePrefix, e);
    } catch (IOException e) {
        AndroidCompileUtil.reportException(context, messagePrefix, e);
    }
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) ArrayList(java.util.ArrayList) List(java.util.List) AndroidCompilerMessageKind(org.jetbrains.android.util.AndroidCompilerMessageKind) IOException(java.io.IOException) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 32 with AndroidPlatform

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

the class AndroidAutogenerator method runRenderscript.

private static void runRenderscript(@NotNull final AndroidFacet facet, @NotNull final CompileContext context) {
    final Module module = facet.getModule();
    final ModuleCompileScope moduleCompileScope = new ModuleCompileScope(module, false);
    final VirtualFile[] files = moduleCompileScope.getFiles(AndroidRenderscriptFileType.INSTANCE, true);
    facet.clearAutogeneratedFiles(AndroidAutogeneratorMode.RENDERSCRIPT);
    for (final VirtualFile file : files) {
        final RenderscriptAutogenerationItem item = ApplicationManager.getApplication().runReadAction(new Computable<RenderscriptAutogenerationItem>() {

            @Nullable
            @Override
            public RenderscriptAutogenerationItem compute() {
                final AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
                if (platform == null) {
                    context.addMessage(CompilerMessageCategory.ERROR, AndroidBundle.message("android.compilation.error.specify.platform", module.getName()), null, -1, -1);
                    return null;
                }
                final IAndroidTarget target = platform.getTarget();
                final String sdkLocation = platform.getSdkData().getPath();
                final String packageName = AndroidUtils.computePackageName(module, file);
                if (packageName == null) {
                    context.addMessage(CompilerMessageCategory.ERROR, "Cannot compute package for file", file.getUrl(), -1, -1);
                    return null;
                }
                final String resourceDirPath = AndroidRootUtil.getResourceDirPath(facet);
                assert resourceDirPath != null;
                final String sourceRootPath = AndroidRootUtil.getRenderscriptGenSourceRootPath(facet);
                if (sourceRootPath == null) {
                    return null;
                }
                final String rawDirPath = resourceDirPath + '/' + SdkConstants.FD_RES_RAW;
                return new RenderscriptAutogenerationItem(sdkLocation, target, sourceRootPath, rawDirPath);
            }
        });
        if (item == null) {
            continue;
        }
        File tempOutDir = null;
        try {
            tempOutDir = FileUtil.createTempDirectory("android_renderscript_autogeneration", "tmp");
            final VirtualFile vTempOutDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempOutDir);
            final String depFolderPath = vTempOutDir != null ? getDependencyFolder(context.getProject(), file, vTempOutDir) : null;
            final Map<CompilerMessageCategory, List<String>> messages = AndroidCompileUtil.toCompilerMessageCategoryKeys(AndroidRenderscript.execute(item.mySdkLocation, item.myTarget, file.getPath(), tempOutDir.getPath(), depFolderPath, item.myRawDirPath));
            if (messages.get(CompilerMessageCategory.ERROR).size() == 0) {
                final List<File> newFiles = new ArrayList<File>();
                AndroidCommonUtils.moveAllFiles(tempOutDir, new File(item.myGenDirPath), newFiles);
                for (File newFile : newFiles) {
                    final VirtualFile newVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(newFile);
                    if (newVFile != null) {
                        patchAndMarkGeneratedFile(facet, AndroidAutogeneratorMode.RENDERSCRIPT, newVFile);
                    }
                }
                final File bcFile = new File(item.myRawDirPath, FileUtil.getNameWithoutExtension(file.getName()) + ".bc");
                final VirtualFile vBcFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(bcFile);
                if (vBcFile != null) {
                    facet.markFileAutogenerated(AndroidAutogeneratorMode.RENDERSCRIPT, vBcFile);
                }
            }
            ApplicationManager.getApplication().runReadAction(new Runnable() {

                @Override
                public void run() {
                    if (module.getProject().isDisposed()) {
                        return;
                    }
                    for (final CompilerMessageCategory category : messages.keySet()) {
                        final List<String> messageList = messages.get(category);
                        for (final String message : messageList) {
                            context.addMessage(category, message, file.getUrl(), -1, -1);
                        }
                    }
                }
            });
            final VirtualFile genDir = LocalFileSystem.getInstance().findFileByPath(item.myGenDirPath);
            if (genDir != null) {
                genDir.refresh(false, true);
            }
        } catch (final IOException e) {
            LOG.info(e);
            ApplicationManager.getApplication().runReadAction(new Runnable() {

                @Override
                public void run() {
                    if (module.getProject().isDisposed())
                        return;
                    context.addMessage(CompilerMessageCategory.ERROR, e.getMessage(), file.getUrl(), -1, -1);
                }
            });
        } finally {
            if (tempOutDir != null) {
                FileUtil.delete(tempOutDir);
            }
        }
    }
}
Also used : CompilerMessageCategory(com.intellij.openapi.compiler.CompilerMessageCategory) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) IAndroidTarget(com.android.sdklib.IAndroidTarget) IOException(java.io.IOException) ModuleCompileScope(com.intellij.compiler.impl.ModuleCompileScope) Module(com.intellij.openapi.module.Module) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 33 with AndroidPlatform

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

the class ModuleClassLoader method create.

@Nullable
public static ClassLoader create(IAndroidTarget target, Module module) throws Exception {
    AndroidPlatform androidPlatform = AndroidPlatform.getInstance(module);
    if (androidPlatform == null) {
        return null;
    }
    AndroidTargetData targetData = androidPlatform.getSdkData().getTargetData(target);
    LayoutLibrary library = targetData.getLayoutLibrary(module.getProject());
    if (library == null) {
        return null;
    }
    return get(library, module);
}
Also used : LayoutLibrary(com.android.ide.common.rendering.LayoutLibrary) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) AndroidTargetData(org.jetbrains.android.sdk.AndroidTargetData) Nullable(org.jetbrains.annotations.Nullable)

Example 34 with AndroidPlatform

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

the class AndroidToolWindowFactory method checkFacetAndSdk.

private static void checkFacetAndSdk(Project project, @NotNull final ConsoleView console) {
    final List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
    if (facets.size() == 0) {
        console.clear();
        console.print(AndroidBundle.message("android.logcat.no.android.facets.error"), ConsoleViewContentType.ERROR_OUTPUT);
        return;
    }
    final AndroidFacet facet = facets.get(0);
    AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
    if (platform == null) {
        console.clear();
        final Module module = facet.getModule();
        if (!AndroidMavenUtil.isMavenizedModule(module)) {
            console.print("Please ", ConsoleViewContentType.ERROR_OUTPUT);
            console.printHyperlink("configure", new HyperlinkInfo() {

                @Override
                public void navigate(Project project) {
                    AndroidSdkUtils.openModuleDependenciesConfigurable(module);
                }
            });
            console.print(" Android SDK\n", ConsoleViewContentType.ERROR_OUTPUT);
        } else {
            console.print(AndroidBundle.message("android.maven.cannot.parse.android.sdk.error", module.getName()) + '\n', ConsoleViewContentType.ERROR_OUTPUT);
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo)

Example 35 with AndroidPlatform

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

the class AndroidModuleConverter1 method process.

@Override
public void process(ModuleSettings moduleSettings) throws CannotConvertException {
    Element confElement = AndroidConversionUtil.findAndroidFacetConfigurationElement(moduleSettings);
    assert confElement != null;
    Element platformNameElement = AndroidConversionUtil.getOptionElement(confElement, PLATFORM_NAME_ATTRIBUTE);
    String platformName = platformNameElement != null ? platformNameElement.getAttributeValue(AndroidConversionUtil.OPTION_VALUE_ATTRIBUTE) : null;
    if (platformName == null)
        return;
    removeOldDependencies(moduleSettings, platformName);
    confElement.removeContent(platformNameElement);
    Library androidLibrary = LibraryTablesRegistrar.getInstance().getLibraryTable().getLibraryByName(platformName);
    if (androidLibrary != null) {
        AndroidPlatform androidPlatform = AndroidPlatform.parse(androidLibrary, null, null);
        if (androidPlatform != null) {
            IAndroidTarget target = androidPlatform.getTarget();
            Sdk androidSdk = AndroidSdkUtils.findAppropriateAndroidPlatform(target, androidPlatform.getSdkData(), false);
            if (androidSdk == null) {
                androidSdk = AndroidSdks.getInstance().create(target, androidPlatform.getSdkData().getLocation(), false);
                if (androidSdk != null) {
                    final SdkModificator modificator = androidSdk.getSdkModificator();
                    for (OrderRootType type : OrderRootType.getAllTypes()) {
                        for (VirtualFile root : androidLibrary.getFiles(type)) {
                            modificator.addRoot(root, type);
                        }
                    }
                    modificator.commitChanges();
                }
            }
            if (androidSdk != null) {
                addNewDependency(moduleSettings, androidSdk.getName());
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OrderRootType(com.intellij.openapi.roots.OrderRootType) Element(org.jdom.Element) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Library(com.intellij.openapi.roots.libraries.Library) IAndroidTarget(com.android.sdklib.IAndroidTarget) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator)

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