现在的 IntelliJ Idea 12 + Android + Scala

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16750642/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 05:19:34  来源:igfitidea点击:

IntelliJ Idea 12 + Android + Scala nowadays

androidscalaubuntuideintellij-idea

提问by Alan Coromano

As suggested to me, I've run through a few articles describing how to make IntelliJ Idea and Android and Scala work together, but it turned out they were all written 1 or 2 years ago. And likely, something has changed since that time and now there are other solutions to achieve this goal. Concretely, there is a new solution https://github.com/yareally/android-scala-intellij-no-sbt-pluginfor which I don't know if it works well or not.

正如我所建议的,我已经阅读了一些描述如何使 IntelliJ Idea 与 Android 和 Scala 协同工作的文章,但结果它们都是在一两年前编写的。很可能,从那时起,事情发生了变化,现在有其他解决方案可以实现这一目标。具体来说,有一个新的解决方案https://github.com/yareally/android-scala-intellij-no-sbt-plugin我不知道它是否有效。

I have IntelliJ Idea 12, Android SDK, Scala, SBT and all other stuff installed and set up. The only thing remaining is to setup IntelliJ Idea 12 to make it work with Scala instead of Java for creating Android applications.

我安装并设置了 IntelliJ Idea 12、Android SDK、Scala、SBT 和所有其他东西。剩下的唯一事情是设置 IntelliJ Idea 12 以使其与 Scala 而不是 Java 一起使用来创建 Android 应用程序。

Please don't close the question. I saw the previous questions similar to mine, but, as I said, they were outdated.

请不要关闭问题。我看到以前的问题与我的相似,但是,正如我所说,它们已经过时了。

The question is, how do I do it now (May 2013)?

问题是,我现在该怎么做(2013 年 5 月)

P.S. I tried Android Development Studio but I even wasn't able to launch it due to many errors.

PS 我试过 Android Development Studio 但由于很多错误我什至无法启动它。

采纳答案by F.X.

Update:You can read the tutorialI wrote about the upcoming new version of SBT-Android (0.7). Most of your concerns should be addressed there. If they are not, then that's a problem.

更新:您可以阅读我写的关于即将推出的 SBT-Android (0.7) 新版本的教程。您的大部分担忧都应该在那里得到解决。如果他们不是,那就是一个问题。



Update 2:For fairness's sake, there's also a great work in progress : android-sdk-pluginby @pfn on GitHub.

更新 2:为了公平起见,还有一项伟大的工作正在进行中:@pfn 在 GitHub 上的android-sdk-plugin

Regarding ProGuard and build times :

关于 ProGuard 和构建时间:

  • I am, myself, preloading large librarieson my device with sbt-android. This eliminates ProGuard altogether, but requires root.

  • android-sdk-plugin's latest version boasts a new ProGuard cache (same as AndroidProguardScala), which is pretty sweet and does eliminate ProGuard in most cases during development.

  • 我自己在我的设备上预加载sbt-android. 这完全消除了 ProGuard,但需要 root。

  • android-sdk-plugin的最新版本拥有一个新的 ProGuard 缓存(与AndroidProguardScala相同),这非常棒,并且在开发过程中的大多数情况下确实消除了 ProGuard。



I've been contributing to SBT-Androidfor a few months now, so I know it a lot better than the other solutions.

我已经为SBT-Android贡献了几个月的时间,所以我比其他解决方案更了解它。

As of now, the plugin is evolving rapidly, with :

截至目前,该插件正在迅速发展,具有:

  • Full IntelliJ support (thanks to SBTIdea) coming very soon (In fact, it already works, I just need to send the pull requests)
  • Automatically preload Scala on an emulator, or rooted device (Just run android:preload-{device, emulator}, no Proguard needed for development anymore!)
  • Should support simple Gradle projects out-of-the-box with minimal effort (The directory structure is very similar)
  • Configuration is a lot easier (Just add the plugin and a project fileand you're set!)
  • 完整的 IntelliJ 支持(感谢SBTIdea)很快就会出现(事实上​​,它已经可以工作了,我只需要发送拉取请求)
  • 在模拟器或root设备上自动预加载Scala (只需运行android:preload-{device, emulator},开发不再需要Proguard!)
  • 应该以最少的努力支持开箱即用的简单 Gradle 项目(目录结构非常相似)
  • 配置要容易得多(只需添加插件和项目文件即可!)

The current version doesn't have most of these niceties, but they're coming up in the following weeks. Some documentation is of course going to follow very soon afterwards, with examples and everything I'll think of.

当前版本没有这些细节中的大部分,但它们会在接下来的几周内出现。一些文档当然会很快跟进,包括示例和我会想到的所有内容。

I encourage you to join the Scala on AndroidGoogle Group and share your thoughts, by the way. There's also a #sbt-androidchannel on Freenode if you're into IRC.

顺便说一下,我鼓励您加入Scala on AndroidGoogle Group 并分享您的想法。#sbt-android如果您喜欢 IRC,Freenode上还有一个频道。

回答by drhr

Just wanted to chime in on this. I used https://github.com/yareally/android-scala-intellij-no-sbt-plugin, although I found the instructions to be vague, not having ever used IntelliJ before this.

只是想插一句。我使用了https://github.com/yareally/android-scala-intellij-no-sbt-plugin,虽然我发现说明含糊不清,在此之前从未使用过 IntelliJ。

You've probably got it all sorted out by now and are happy with SBT, but for my purposes I just wanted to test Scala on Android without all the extra bells and whistles. So, here are some little things I had to do to get the no-sbt-plugin stuff working:

您现在可能已经全部解决了,并且对 SBT 感到满意,但出于我的目的,我只是想在 Android 上测试 Scala,而不需要所有额外的花里胡哨。所以,为了让 no-sbt-plugin 工作正常,我必须做一些小事:

I ended up including the scala-compiler.jar (along with the scala-library.jar and scala-reflect.jar) as a Global Library: enter image description here

我最终将 scala-compiler.jar(以及 scala-library.jar 和 scala-reflect.jar)包含为全局库: 在此处输入图片说明

That way, the compiler has access to the library & reflection code, otherwise I was getting errors. If you don't include the library, the IDE complains that the compiler needs an associated library, and if you don't include reflect it spits out a bunch of errors at compile time that it cannot find reflect class definitions.

这样,编译器就可以访问库和反射代码,否则我就会出错。如果您不包含该库,IDE 会抱怨编译器需要一个关联的库,如果您不包含反射,它会在编译时吐出一堆找不到反射类定义的错误。

I had to include scala-library.jar as a module dependency as well (which had the side effect of including it under the Libraries section also): enter image description here

我还必须包含 scala-library.jar 作为模块依赖项(这也有将它包含在库部分下的副作用): 在此处输入图片说明

Before doing all that, I had the Scala plugin installed, created an Android project, and simply added a Scala facet (ignore the memory settings, I was fooling around): enter image description here

在做这一切之前,我安装了 Scala 插件,创建了一个 Android 项目,然后简单地添加了一个 Scala 方面(忽略内存设置,我在胡闹): 在此处输入图片说明

Finally, I had to resolve some remaining compilation errors by adding a few "-dontwarn" lines to the proguard txt file. Simple enough.

最后,我不得不通过在 proguard txt 文件中添加一些“-dontwarn”行来解决一些剩余的编译错误。足够简单。

Works like a charm. Haven't done anything substantial with it yet, but am looking forward to using Scala on my next Android project.

奇迹般有效。还没有用它做任何实质性的事情,但我期待在我的下一个 Android 项目中使用 Scala。

回答by pocorall

I wrote the Scaloidlibrary that makes Android development more concisely with Scala.

我编写了Scaloid库,它使用 Scala 使 Android 开发更加简洁。

For a quick starting point, I wrote a hello-worldmaven project for Scala+Android.

为了快速入门,我为 Scala+Android编写了一个hello-worldmaven 项目。

I use Intellij as a main IDE, and it imports the project with a charm.

我使用 Intellij 作为主要 IDE,它以一种魅力导入项目。

回答by ghik

I've gone through this about a month ago and I managed to make it work quite nicely using Gradle.

大约一个月前我已经完成了这个,我设法使用 Gradle 让它很好地工作。

Here is the outcome: https://github.com/ghik/akkdroid

结果如下:https: //github.com/ghik/akkdroid

This is a simple client-server project using Scala and Akka, with client-side on Android, developed with IntelliJ IDEA. I know that client-server doesn't really make sense with Akka, but that's just a simple university project to prove that these technologies can work together.

这是一个简单的客户端 - 服务器项目,使用 Scala 和 Akka,客户端在 Android 上,使用 IntelliJ IDEA 开发。我知道客户端-服务器对 Akka 没有真正意义,但这只是一个简单的大学项目来证明这些技术可以协同工作。

Note however that gradle script in this project is meant only to generate IDEA project, it has to be further extended to be able to perform proper Android application build.

但是请注意,此项目中的 gradle 脚本仅用于生成 IDEA 项目,它必须进一步扩展才能执行正确的 Android 应用程序构建。

回答by Madwyn

I have been watching this thread for several months, finally got some time to do the real tests.

我一直在看这个帖子几个月,终于有时间做真正的测试了。

Using IntelliJ 13 with SBT 0.13 and Scala 2.10.3.

使用 IntelliJ 13 和 SBT 0.13 和 Scala 2.10.3。

  1. The SBT-Androidhasn't been updated for several months. I found the instructions were outdated and I didn't manage to create a working project.

  2. The android-sdk-pluginworked. Just followed the simple steps and I got "hello world" running on my phone. But importing the SBT project into IntelliJ will not work properly, will need some project modifications manually.

  3. I have also tried to create an Android project first then add Scala framework, but didn't work out as I was expecting.

  1. SBT-的Android一直没有更新了好几个月。我发现说明已经过时了,我没有设法创建一个工作项目。

  2. Android的SDK-plugin的工作。只需按照简单的步骤操作,我的手机上就会运行“hello world”。但是将 SBT 项目导入 IntelliJ 将无法正常工作,需要手动修改一些项目。

  3. 我也尝试先创建一个 Android 项目,然后添加 Scala 框架,但没有像我预期的那样成功。