Scala Programming for Android

我与影子孤独终老i 提交于 2019-12-17 06:57:10

问题


I have followed the tutorial at Scala and Android with Scala 2.7.3 final. The resulting Android App works but even the most basic application takes several minutes (!) to compile and needs 900 kb compressed, 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.

  • So my question is: Has anyone actually done this and is there any cure for this?

回答1:


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 jar files.

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

Proguard is not the only solution, you might find something that suits your work flow or is more suited for your environment.

Additionally google have just realised JACK , which deals with quite a lot of reducing build and memory times see https://source.android.com/source/jack.html




回答2:


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.

https://github.com/jvoegele/gradle-android-plugin/wiki




回答3:


There is also an plugin for the Scala-based builder sbt: sbt-android-plugin.




回答4:


For tutorials and examples, see also Stéphane Micheloud's "Exploring Android" page: http://lamp.epfl.ch/~michelou/android/




回答5:


I verified this detailed solution with Eclipse 3.7, Scala 2.10 and the plug-in AndroidProguardScala v50:

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.




回答6:


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.

Please note that this question is a typical example of a question with outdated answers on Stack Overflow. This answer will likely become outdated at some point as well.

* 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.




回答7:


If you use maven, use android-scala-test as a startup template. It works great for me out-of-the-box.

Scaloid is an Android API wrapper written in Scala that help you to write your Android program in Scala-style.




回答8:


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

Gradle is more native building tool for android than SBT.

There is good example of Scala client and server side solution concept, and gradle building tool as advance for IntelliJ IDEA workbench.

Big advance that core classes are common for client and server.

https://github.com/ghik/akkdroid

Good tutorial for IDEA and android-plugin: http://fxthomas.github.io/android-plugin/




回答9:


The biggest issue with Scala on Android is the compile times.

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.

I simply moved back to Java after completing a largish Scala Android project as compile times were too frustrating.



来源:https://stackoverflow.com/questions/476111/scala-programming-for-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!