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.
Related
I'm fairly new to Kotlin and I noticed that the API docs tend to have differing support for the major Kotlin platform targets JVM, JS, and Native (I'm asssuming Common means it should be supported the same everywhere). My use case for Kotlin is Android development, but so far I haven't found a definitive answer as to what platform target compatibility building for Android implies. Presumably it would be JVM since kotlinc does compile Java bytecode as the first step in and Android build, but that's confusing and unintuitive since Android has nothing to do with the JVM itself. In the Kotlin FAQs describing what Kotlin is, they mention Android as a target platform; however, Android is not listed in the Platforms heading of their documentation (only JVM, JS, Native, and Scripting).
Is Kotlin targeting the JVM with respect to its API when programming for Android? If not, what platform(s) is/are applicable when browsing the Kotlin docs for the purposes of Android development?
Yes, on Android Kotlin compiles into and is run on the JVM. That's why it interacts with existing Java code/libraries and the Android framework (which is written in Java)
Since 2 Years I am working as Android Application Developer. I generally use android SDK for all the Android Apps Development. Now I have a project which is an Android App in which I have to use SDK as well as NDK for App development (As per Client requirement).
But as I don't have any experience with NDK I don't know what is it. In some Blogs I have read that NDK development is based on c++.
Is it true that to work with NDK one must have the complete knowledge of c++ ?
Please Help !!
Use of NDK means you have to write portion of code in C/C++ just to achieve the speed. If it is client requirement then you have no option. But keep in mind that you should use NDK only when you feel you need better performance. And of course you must have some understanding of c/c++ to use NDK.
NDK
NDK is a set of tools to compile C code to shared lib,
which you could use in your app - and that's all.
Enables legacy code re-use between iOS and Android platforms
Good for implementing CPU intensive operations that don't
allocate much memory like signal processing, physics simulations.
SDK
SDK is the main development kit for Android apps - it contains tools for Java and resources (png, xml) compiling, packaging to apk file, installing, running and debugging them on a device, an emulator, documentation, etc.
Java has superior memory management model Superior threading model Better exception handling model Rich set of libraries Superior support for unicode characters.
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.
I have been asked to research on how to make an android app using Delphi, Now I am not sure that this can be done. I have not come across tutorials on the same. Somebody please clarify on this issue.
Delphi cannot create Android apps at present. This is being worked on for a future release.
Update: As of the release of XE5, Delphi now supports Android development for certain ARM hardware using the mobile Delphi compiler.
Free Pascal is now able to produce code for the Java platform - so it might be feasible to create Delphi code which can be compiled to Java bytecode with FPC and then converted for the Dalvik VM.
The FPC backend for the Java Virtual Machine (JVM) generates Java byte
code that conforms to the specifications of the JDK 1.5 (and later).
While not all FPC language features work when targeting the JVM, most
do (or will in the future) and we have done our best to introduce as
few differences as possible.
This FPC JVM backend is not related to Project Cooper by RemObjects,
nor does FPC now support the Oxygene language.
Two choices to follow at present - check out Delphi for Android which is in design/beta phase: http://lenniedevilliers.blogspot.com/
Or, use Prism http://www.embarcadero.com/products/prism (and check out their Oxygen for Java coming soon http://www.remobjects.com/oxygene/java.aspx which is in Beta)
With DWS as backend script compiler and the soon to come Smart Mobile Studio (aka OP4JS) component library and RAD interface it will be possible to make apps running with HTML5 in android applications (and iOS or any other html5 compatible system).
By using object pascal, all Delphi and freepascal users will have a short learning curve and a high code reuse factor.
There are some samples using only the DWS backend here :
taming-the-flock-with-object-pascal
taming-html5-verlets-with-object-pascal
Update :
More samples can now be found on their homepage.
First steps with native Android applications made with Lazarus/FPC are here.
One way is to use a combination of Delphi, Sencha and PhoneGap by leveraging the Raudus framework. You can try the RaudusEmployee.apk example on your phone and see if this method will work for you.
http://www.raudus.com/samples/
This is not a native application, but similar to many new HTML5 applications.
Delphi XE5 is now released with Android support.
http://www.embarcadero.com/products/rad-studio/create-android-apps
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.