Scala, Android and Eclipse - android

I've started learning Scala, and I... I think I'm in love. I've only coded small test snippets so far, but since I currently working in Android development, what I really want to do is try my hand at writing Android applications in Scala.
I've found articles and questions on the matter, but mostly referring to older versions of the three tools (Android SDK/Scala/Eclipse), so the general question is:
Is anybody coding Android apps in Scala right now, with the latest SDK, Scala 2.9 and Eclipse Indigo? How viable is it?
And, in particular:
How's the interaction/integration between Scala's features and the Android library?
What's the state of the Scala plugin for Eclipse? I've read all the features you'd expect are there, but I'd like to know first-hand stories, specially about the debugger.
How well does the build process (scala to java to dalvik, ant, proguard, etc.) automate?
Thanks!

We are using Scala heavily to test our Android code - you can read a writeup of how we're doing so here. We use Ant or SBT to compile - there's an excellent SBT plugin for Android development.
Having said all of that, I'm not sure that I would recommend Scala for production Android development. In particular Scala 2.9.x is basically unusable as there is no good way to get the libraries to work on Android. You can read about the issue here.
It's a real pity, as Android development would benefit considerably from Scala if we could get it working properly.

Solution found here to use the latest Android SDK, with Eclipse 3.7.2 and Scala 2.9 :
https://stackoverflow.com/a/11084146/1287856
It completely handles the android library
You can make Android Library out of scala projects as usual
The build process is completely automated, including proguard-ing and exporting the project with the regulard Android tools.

I started to implement the android application (a twitter client) from the book "Learning Android" with Scala 2.9.0-1 a while ago.
In my opinion you can use it. I had only one problem with the parameter list at AsyncTask (see this link, problem #3).
If you want to checkout out the project, you can find it here.

This video from ScalaDays 2011 may be hepful:
Scala on Android: Real-world Experience at Bump Technologies by Michael Galpin
EDIT:
If you really really want to run Scala code on Android (and not really make an app, but for yourself), then I have an easier solution. It depends on if your phone supports the procedure. In summary the steps are:
Install Ubuntu on your device (as described here). This will not affect the Android installation.
Boot Ubuntu, install JDK, Scala, etc, copy your Scala jars and run from there.

Related

Using Scala for Android development

I'm not an android developer nor a java expert but I've been searching a lot for developing android apps using Scala lately. I found some things like Scala on Android and also a lot of questions and answers here as well but most of them are outdated (they're mostly between 2013 to 2017). Also, Scala on Android's last release was in 2017. So, I guess there wasn't a really big improvement there.
I read somewhere that the main issue is lambda expressions in java but that make no sense. What is the real reason that holds developers from using Scala in android?
I know that Kotlin is the preferred way to develop android but is there any way to develop the whole app in Scala? Is it even possible? if it is, is it a good idea?
What about Scala 3? Is there any hope that the new version of Scala have a future for android development?
The broad reason is that the maintainers of the official Scala compiler made a decision to only emit bytecode targeting Java virtual machine versions for which Google did not (at the time) support compiling into Dalvik. (The Oracle v. Google legal proceedings may have influenced Google's decision).
In the interim, Google has added support for some Java 8 features. However, the support is not complete, and Scala uses some features which Google's tooling doesn't support.
This scala-lang.org discussion covers some of the major hoops which had to be jumped through to build an Android app in 2.13; it included patching the Scala standard library in order to make the collections work. It does look like there's a chance Scala 2.13.7 will be patched to address at least some of the issues.
In the meantime, the historical Scala on Android project had largely been abandoned; there is apparently the beginnings of an effort to begin a new project based on Scala 2.13 and Scala 3.

How to use Android Studio with Cocos2d-x

I work as an android programmer for just under a year now, and I just started to learn about android game development. The framework I choose to work with is Cocos2d-x.
I have seen guides and tutorials on how to use Cocos2d-x with eclipse, but I'd really like to know if it's possible to be used with Android Studio.
From what I've read, it is now possible to build NDK projects with gradle in Android Studio, which is good news. Nevertheless, I have yet to find any information about C++ programming using Android Studio. Eclipse uses the CDC ( https://www.eclipse.org/cdt/ ) plugin to achieve this.
Is there anything similar to be used with Android Studio? I have found some C/C++ enabling plugins for the IntelliJ Platform, but they were no longer updated.
Has anyone else tried this before? Did it work? Can you provide a step-by-step guide, for a newbie like me, who's dealing with this kind of problems for the first time?
Thank you for you time,
haxm
Android Studio currently isn't well set-up for native programming. While the build system supports the NDK, there's no editor support for C++ files (it's not as if it won't work, but the IDE won't give you any editing assistance), and neither is there any debugging support. JetBrains has announced that they're working on new C++ support for IntelliJ, and this is something we're looking at for Android Studio, but it's not on the roadmap yet.
Recent version of cocos2dx v3 (from github for example)
have proj.android-studio project
At this moment I have no success to build it but maybe in future it will be fixed
I just went through the setup for this example code. The project compiles and has a ton of sample code. Scott Barta's answer still stands as an important caveat, but wanted to share the link in case it was useful.
I also found this useful for some NDK background/how-to.

Scala on Android using Netbeans (preferably 6.8)

I have tried Scala on Android using various suggestions found on the Internet. However, I have never been able to get a "one-click" solution for Netbeans. Eventually I settled for Java + Eclipse. However, the urge to create Scala programs on Android persists.
Has anyone successfully used Netbeans IDE for Scala development for the Android platform? And that too using the IDE's build tools?
Ideally the following features are needed:
Scala code completion, syntax highlighting, error checking (as in NB-6.8 + Scala 2.8)
Automatic deployment on Android using one-click
No messing around with Proguard config
No messing around with signing of the jars/apks
Please post a step-by-step guide if this is possible, or please link to an external page giving details.
Have you tried the new eclipse plugin? Those are a major improvement from a few month ago. There should be versions for 2.9.1 and (if you need scala 2.8 ) Scala 2.8.2 see www.scala-ide.org

Differences between Android NetBEANS plugin and Eclipse plugin?

Would like to know the main differences between the Android NetBEANS plugin and Eclipse plugin ? Do you have a visual editor in both or one of both ? Do you have more support on Eclipse ?
Thanks.
I think its a matter of personal preference, but I think Eclipse with ADT plugin is recommended by Google for good reasons.
ADT simplifies things by generating build scripts for you and allows you to drag and drop files into your project and auto generates references in R.Java file.
It sounds to me that you might be new to Android/Java development? If that's the case then my personal opinion is stick with the Google recommendations. It saves you a lot of time getting your first android application up and running and I think that's the goal for most people starting a new development language.
I develop almost everything in NetBeans. However, for Android application development, Eclipse is the better IDE to use, as it simplifies a lot of simple tasks.
I prefer NetBeans generally, but Eclipse is way more tailored to Android development than NetBeans at the moment.
You will be more productive :
Android offers an Eclipse Plugin per their web site. Check out this link on the Android site: http://developer.android.com/sdk/installing/index.html. For the beginning programmer new to Android the tight integration will allow ramp up to speed faster. One of the most highly regarded reference works by Reto Meier "Professional Android 4 Application Development" recommends Eclipse with the ADT Plug-in and makes no mention of Netbeans.
The ADT Plugin includes an Android Project Wizard, Virtual Device Manager and Emulator and especially the layout and resource editors for XML. Therefore you get the tightest integration to make it easiest for a programmer to ramp up quickly and begin to develop Android applications.
Android recommends Eclipse and the plugin, as do respected developers like Reto Meier over Netbeans. (Despite the fact that a plugin does exist for Netbeans as helpfully provided below.)
My recommendation if you are new to Android development, use the Eclipse with ADT Plug-in. If you are a Netbeans veteran, stick with that.

Scala Programming for Android

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?
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
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
There is also an plugin for the Scala-based builder sbt: sbt-android-plugin.
For tutorials and examples, see also Stéphane Micheloud's "Exploring Android" page: http://lamp.epfl.ch/~michelou/android/
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.
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.
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.
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/
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.

Categories

Resources