Android Scala 编程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/476111/
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
Scala Programming for Android
提问by Lemmy
I have followed the tutorial at Scala and Androidwith Scala 2.7.3final. The resulting Android App works but even the most basic application takes several minutes (!) to compile and needs 900 kbcompressed, which is a show stopper for mobile applications. Additionally, the IDE runs out of memory every now and then. I assume dex
is not made for big libraries like the scala-library
.
我已经按照Scala 和 Android的教程使用Scala 2.7.3final。生成的 Android 应用程序可以运行,但即使是最基本的应用程序也需要几分钟 (!) 编译并需要900 kb压缩,这对于移动应用程序来说是个障碍。此外,IDE 时不时会耗尽内存。我认为dex
不是为像scala-library
.
- So my question is: Has anyone actually done this and is there any cure for this?
- 所以我的问题是:有没有人真的这样做过,有没有办法解决这个问题?
回答by Lemmy
I've written some basic Android applications in Scala, nothing too epic. Not being a Java programmer I was suggested to use a "treeshake", I was explained by a friend that this strips out all the unnecessary libraries from the jarfiles.
我已经用 Scala 编写了一些基本的 Android 应用程序,没什么特别的。我不是 Java 程序员,有人建议我使用“treeshake”,一位朋友向我解释说,这会从jar文件中删除所有不必要的库。
I have not documented it, but I found that someone else already has:
我没有记录它,但我发现其他人已经有了:
http://chneukirchen.org/blog/archive/2009/04/programming-for-android-with-scala.html
http://chneukirchen.org/blog/archive/2009/04/programming-for-android-with-scala.html
Proguard is not the only solution, you might find something that suits your work flow or is more suited for your environment.
Proguard 不是唯一的解决方案,您可能会找到适合您的工作流程或更适合您的环境的解决方案。
Additionally google have just realised Hyman , which deals with quite a lot of reducing build and memory times see https://source.android.com/source/Hyman.html
此外,谷歌刚刚实现了 Hyman ,它处理了大量减少构建和内存时间的问题,请参见https://source.android.com/source/Hyman.html
回答by Jason Voegele
You can now use the Android plugin for Gradle to create Android applications in Scala. It incorporates the ProGuard tool to trim the fat from the resulting APK file, so seems to meet your needs.
您现在可以使用 Gradle 的 Android 插件在 Scala 中创建 Android 应用程序。它结合了 ProGuard 工具来修剪生成的 APK 文件中的脂肪,因此似乎可以满足您的需求。
回答by Jan Berkel
There is also an plugin for the Scala-based builder sbt: sbt-android-plugin.
还有一个基于 Scala 的构建器sbt的插件:sbt-android-plugin。
回答by Lukas Rytz
For tutorials and examples, see also Stéphane Micheloud's "Exploring Android" page: http://lamp.epfl.ch/~michelou/android/
有关教程和示例,另请参阅 Stéphane Micheloud 的“探索 Android”页面:http://lamp.epfl.ch/~michelou/android/
回答by Mika?l Mayer
I verified this detailed solution with Eclipse 3.7, Scala 2.10 and the plug-in AndroidProguardScala v50:
我用 Eclipse 3.7、Scala 2.10 和插件 AndroidProguardScala v50 验证了这个详细的解决方案:
https://stackoverflow.com/a/11084146/1287856
https://stackoverflow.com/a/11084146/1287856
Everything works fine. A simple test application with scalafied main activity class only takes 38Kb. Libraries projects are supported. Proguard is activated when exporting the project.
一切正常。带有扩展的主活动类的简单测试应用程序只需要 38Kb。支持图书馆项目。导出项目时会激活 Proguard。
回答by DCKing
Developing Android apps for Scala is continuously evolving. The current best way to do it appears to SBT in conjunction with the android-sdk-plugin, which is maintained* and works well for me in my Scala/Android project. A somewhat recent example that demonstrates the use of this plugin with the already mentioned Scaloid can also be found.
为 Scala 开发 Android 应用程序在不断发展。目前最好的方法是将 SBT 与android-sdk-plugin结合使用,该插件得到维护*并且在我的 Scala/Android 项目中对我来说效果很好。还可以找到一个最近的例子,它演示了这个插件与已经提到的 Scaloid 的使用。
Please note that this question is a typical example of a question with outdated answerson Stack Overflow. This answer will likely become outdated at some point as well.
请注意,此问题是Stack Overflow 上答案过时的问题的典型示例。这个答案在某些时候也可能会过时。
* The other SBT based projects mentioned in this answer thread don't appear to have code being written for them in the last six months at the time of writing. They may have compatibility issues with newer versions of Scala and SBT.
* 在撰写本文时的最后六个月内,此答案线程中提到的其他基于 SBT 的项目似乎没有为它们编写代码。它们可能与较新版本的 Scala 和 SBT 存在兼容性问题。
回答by pocorall
If you use maven, use android-scala-testas a startup template. It works great for me out-of-the-box.
如果您使用 maven,请使用android-scala-test作为启动模板。它非常适合我开箱即用。
Scaloidis an Android API wrapper written in Scala that help you to write your Android program in Scala-style.
Scaloid是用 Scala 编写的 Android API 包装器,可帮助您以 Scala 风格编写 Android 程序。
回答by mikowiec
You can use the Scala on Android without SBT, it built externally by Gradle to create Android applications. https://github.com/yareally/android-scala-intellij-no-sbt-plugin
您可以在没有 SBT 的情况下在 Android 上使用 Scala,它由 Gradle 在外部构建以创建 Android 应用程序。 https://github.com/yareally/android-scala-intellij-no-sbt-plugin
Gradle is more native building tool for android than SBT.
Gradle 是比 SBT 更适合 android 的原生构建工具。
There is good example of Scala client and server side solution concept, and gradle building tool as advance for IntelliJ IDEA workbench.
有很好的 Scala 客户端和服务器端解决方案概念示例,以及作为 IntelliJ IDEA 工作台的高级构建工具的 gradle 构建工具。
Big advance that core classes are common for client and server.
核心类对于客户端和服务器来说是通用的,这是一个巨大的进步。
https://github.com/ghik/akkdroid
https://github.com/ghik/akkdroid
Good tutorial for IDEA and android-plugin: http://fxthomas.github.io/android-plugin/
IDEA 和 android-plugin 的好教程:http: //fxthomas.github.io/android-plugin/
回答by mikowiec
The biggest issue with Scala on Android is the compile times.
Scala 在 Android 上的最大问题是编译时间。
Possibly because of the Proguard class stripping compiles with IDEA13/Scala plugin on a Dual Quad Core (8-CPU) E5450 Xeon with 8GB can take two minutes or more.
可能是因为 Proguard 类剥离在双四核 (8-CPU) E5450 Xeon 8GB 上使用 IDEA13/Scala 插件编译可能需要两分钟或更长时间。
I simply moved back to Java after completing a largish Scala Android project as compile times were too frustrating.
在完成一个大型 Scala Android 项目后,我只是简单地回到了 Java,因为编译时间太令人沮丧了。