Android without Java

2019-03-08 14:51发布

问题:

After doing the whole "enterprise" programming for a while, I'm seriously disillusioned by the language itself and always feel quite hampered if I have to go back to it. The project size of your average Android app isn't too intimidating and the libraries are actually quite nice regarding their coding style, but if I could avoid Java, I'd certainly do.

So that's the question: Can I avoid it? While there are lots of JVM language that would be an option on desktops and servers, the Dalvik VM and the devices themselves pose some limits. This seems to be a bit better in 2.2 with the JIT, but limiting myself to the cutting edge would be a rather harsh decision.

The only alternative I know that's used somewhat seems to be Scala. Is there some possibility I'm missing? Clojure seems to run in exactly the problems I've illustrated above with Dalvik, but as the AppInventor is built on Kawa there might be hope for a Lisp on the mobile platform?

What other languages are already usable or make strides towards that?

回答1:

Personally, I'd say Scala is your best bet right now. It works really well, with the one drawback being that you are required to include Scala as a dependency (which will increase the size of your application).

  • Scala Programming for Android
  • Can I program for Android using any JVM language?
  • Getting Started Programming in Dynamic Languages in Android


回答2:

Have you looked at Mirah? It gives you a Ruby-like syntax and compiles to Java. It’s been labeled the CoffeeScript of Java.



回答3:

Is there some possibility I'm missing?

Tons of 'em!

Clojure seems to run in exactly the problems I've illustrated above with Dalvik

I'm not aware of this. Any JVM language that is an ahead-of-time compiler (i.e., generates Java bytecode on the developer PC) should work with Dalvik.

but as the AppInventor is built on Kawa there might be hope for a Lisp on the mobile platform

AFAIK, App Inventor is only using Kawa for code generation.

What other languages are already usable or make strides towards that?

Well, there's HTML5 (Javascript), which works OK in offline mode.

Or, there's PhoneGap (HTML+CSS+Javascript).

Or, there's Rhodes (Rails-esque apps in Ruby on the device).

Or, there's Titanium Appcelerator Mobile (HTML+Javascript, but with Javascript hooks to render native UI widgets).

Or, there's Flash, at least for Android 2.2+.

Or, there's AIR...well, OK, that's still in pre-release.

As Elfred noted while I was writing this, there is JRuby with Ruboto.

There are Bedrock, Corona, DroidScript, Flixel, MobiForms, MonoDroid, MoSync, Squeak, and SuperWaba.

There's C/C++ through the NDK, though that's mostly for adding extension libraries to a Java app more so than writing full-on native-code apps.

There's SL4A (formerly the Android Scripting Environment, or ASE), which is your gateway to Python, Perl, Lua, and other scripting languages. As of this moment, you cannot package these scripts up as APKs, but they're working on that.

Now, none of these are going to give you precisely the look of a "regular" Android app. For those, you need a JVM language with ahead-of-time compilation. And there is no question that bog-standard Java Android apps are far and away the most numerous. But unlike some fruit-flavored operating systems that block this sort of thing, you have lots of places to experiment with alternatives to traditional Java coding with Android.

Some balding guy is writing a book that is going to review all of these options, but that's only partially ready right now.



回答4:

This link has some details on how to get scala apps working on android. I'm sure you can do something similar for clojure or other jvm languages.

Ruboto is aiming to bring JRuby in.



回答5:

DroidScript is probably one of the easiest of the above mentioned development tools to use for Android development. Like Cordova you use JavaScript, but unlike Cordova you have the choice of using native Android GUI's or HTML5 to build your App interfaces.

Also you still have access to all the devices sensors/hardware without needing to import loads of complicated plugins. Plus you get the bonus of being able to develop actually on your mobile device if you need to (you can even build APK's and publish them from your device).

I would say its very good for beginners or prototyping but perhaps not flexible enough for seasoned developers.



回答6:

Xamarin Studio let's you build in C#/Mono and build apps for both Android and iOS. Now the presentation layers have to be implemented differently on both platforms, but for the ability to use C#, it's a big Win.



回答7:

You can build an android app with the knowledge of just Html/css/Js. So there is no need of Java to create an android applications. Visit here for some basic knowledge. [1]http://www.chromeearth.com/requirements-cordova-platform/



回答8:

I have never used it, but Kotlin is a new language that runs on the JVM developed by JetBrains (the maker of Android Studio) that deserves a mention. The Kotlin website claims the language is 100% interoperable with Java and has a tutorial for Getting started with Android and Kotlin and Android Studio now actually comes with Kotlin support.