Android Adverse To Dynamic Languages - android

I believe I read at some point that due to Android running on the Dalvik VM, that dynamic languages for the JVM (Clojure, Jython, JRuby etc.) would be hard pressed to obtain good performance on Dalvik (and hence on Android). If I recall correctly, the reasoning was that under the hood, in order to achieve the dynamic typing, there was quite a bit of fiddling done with the java bytecode and that the bytecode->dalvik translation wouldn't pick this up easily.
So should I avoid a dynamic JVM language if I want to develop for Android?
EDIT: I guess I should have provided a bit more context. I was considering using Clojure to develop apps for Android. I was thinking about using Clojure for a few reasons:
I want to learn FP
I don't really care to learn Java
Clojure seems to have some very
interesting language concepts (STM
for example).
However, when I tried to write apps for Android in Clojure, I found that there is a performance issue that is unacceptable. But I found a blog posting that said that dynamically typed languages (Clojure for example) would have problems due to the bytecode manipulation needed to get the dynamic typing. So I was sort of looking for independent confirmation that this is true or it isn't. I should have known better than to make the assumption that in this particular issue all dynamically typed JVM languages could be treated as the same. I guess I did ask a fairly broad question so I guess I shouldn't be surprised that people didn't quite understand what I was asking.

Dan Bornstein gave a presentation on Dalvik at Google I/O. It's worth watching to learn about the system in general, including the constraints you care about. The specific issue of non-Java languages compiled into Java bytecode comes up during the Q&A.
Remco van 't Veer has a github project where he's patched Clojure to work on Android. Tim Riddell has written a tutorial on how to use it.
As mentioned here by #sean, there is sometimes a bigger problem than just performance. Dan Bornstein discusses it when asked about Jython, at ~54:00 in video. There is currently no support for dynamic languages which generate bytecode on-the-fly, (because the bytecode translation is not available at runtime).

Android just got scripting

There are some patches to make clojure work.
http://riddell.us/tutorial/clojure_android/clojure_android.html
I think the real issue is the use of byte code generators by some dynamic languages; they won't generate byte code for the Davlik VM. Therefore eval will not work.

Given the relatively speaking cramped hardware of the phone running you probably should just target java and not worry about a dynamic jvm language. They dynamic languages on the jvm aren't going to be as efficient as the java to my understanding.
Besides the Android SDK is pretty sane and easy to write for I don't think you'll experience very many benefits using something else.

dynamic languages for the JVM would be hard pressed to obtain good performance on Dalvik
Dynamic languages are hard pressed to obtain good performance, period. If you want performance, use a statically typed language like Java (or C#, F# etc.).

Related

Can iOS Apps be developed using Java?

I'm a web developer and am thinking of digging into mobile app development. The languages I know so far are PHP, Python, SQL, Js, HTML and CSS, all of them pretty well now. Currently I'm starting to dig into Java, as it's the language to be used for native Android App Development, as far as I've learned. Interestingly, I'm coming across posts (also in this forum) saying that Java can also be used to develop iOS - compatible Apps, while other sources comment that Apple is completely against cross-devs, and that you should develop iOS apps using Swift when it comes to the native choice and optimal UX. So I was wondering about the answer in this forum; can you develop iOS apps using Java or not?
Post is a few months old now, but I figure someone with a similar question will probably find this with web search, so this reply is for them. (Disclaimer: I wrote Java professionally for about five years, and I grew up when Java was supposed to be the future.)
If the question is, "Can you write Java code and run it on iOS?" then the answer is, "Technically yes, but you almost certainly don't want to."
It requires jumping through all kinds of hoops and sleight-of-hand to make it work. The project linked in a previous answer, Codename One, is a pretty heavyweight framework and the kind of thing you'd only want to use if you were heavily committed to a Java codebase already.
There are advantages to knowing Java in 2022, but cross-platform mobile development isn't one of them.
Some reasons why you might want to learn Java:
Developing on Android. Android now supports/recommends Kotlin for new projects, but Java was the sole first-class language on the platform for 10+ years, so it's advantageous to be able to read/write/reuse Java code and libraries.
Using long-standing big-data tools (spark, hadoop, neo4j, etc.). While this domain has increasingly moved to Python over the past 5-7 years, there's still a lot of production Java code that someone needs to maintain. [Edit 3/31/22: See also the Apache http server, whose name never sat right with me because as far as I know, the people who wrote it aren't Apache.]
Stylistic similarity to C-family languages. Java can be a more intuitive introduction to C-style languages than jumping right into, say C++. These days, though, I would recommend C# over Java since it's used in more domains.
Continuity with some JS dialects. React code in particular is full of Object Oriented(tm) design conventions that are very strongly influenced by Java practices, and those design choices in turn have influenced changes in the JS spec. So being familiar with Java conventions can help make sense of that stuff. It can also help you identify which of those practices are bad ideas so you can avoid them in JS. [See footnote 1.]
As far as reasons why you won't see widespread Java usage outside of those legacy domains, I'd say there are a lot of good reasons people have moved away from Java since 2006 or so:
It's incredibly verbose, and requires a lot of esoteric knowledge about implementation details to write code that runs efficiently. This is the kind of problem that languages like Scala and Kotlin have tried to solve, while retaining compatibility with the JVM platform for ease of migration.
The JVM platform itself introduces substantial overhead, both in resource usage and integration complexity.
Changes in approach and policy since Sun's acquisition by Oracle. This is related to licensing issues (see Oracle v Google), as well as complexity/feature creep, which has given rise to compatibility issues across codebases.
Emergence of viable alternative languages in the 2000's and 2010's.
Widespread adoption of virtualization technology has yielded alternate ways to solve the compatibility issues that Java was designed to address.
It's ironic, since the motto of Java used to be "write once, run everywhere", but that's the way things go.
Footnote 1. Actually, this is kind of a trick question, since most commonly accepted Java practices are bad ideas. This can be demonstrated by the fact that in 1995, object-oriented Java applications would run in a typical web browser, whereas 27 years later Java is considered too heavyweight for that purpose.
Postscript, 3/31/22: This is my first and likely only Stack Overflow post. If you want to read more like this, check out my github: https://github.com/ubuvoid
Yes you can.
One tool used for this is Codename One.
https://www.codenameone.com/
Also for more info on this subject, feel free to consult this thread:
How can one develop iPhone apps in Java?
Yes, this is possible. https://github.com/Anuken/Mindustry is an open-source RTS game written in Java. It has an iOS port that is compiled via an open-source fork of RoboVM.
IOS works on objective C and Android works in Java and Kotlin. I don't know how much some conversion tool can help you to achieve all the functionality. So in my opinion answer is No.
Hybrid Application development can help you. You have one source code that will run in both platform. You have to develop the app again.
First: Java is used in more Domains than C#. Needed information because C# has no way to get over with ONE UI to Desktop, Mobile and Web.
By the way, the recommended Solution is CodenameOne or - if you want to implement your App with JavaFX - use Gluonmobile which is using the GraalVM, an ahead of time compiler for IOS.
In both Cases you have access to Hardware of the Device for Android and IOS because there is an abstraction which helps you with implementations for both Platforms - Android And IOS. Write in this Case one App and compile for both worlds.

Lisp on Android

I'm interested in getting started with Android development and would like to use a Lisp-style language. However, I want something that won't limit me if I choose to write a complex app, so it also needs to have reasonable performance, executable size and startup times. This limits my choices to languages that compile to JVM bytecode that have Android support.
Clojure (Neko)
This would be my first choice because of Clojure's expressiveness, but I have heard that it has problems with slow startup times and poor performance on Android. However, the threads that I came across are quite old so I'd be interested to know if things have improved since then.
Scheme (Kawa)
I came across this option here. Scheme is a nice language, so this option is appealing but it looks like the Android specific libraries it provides may be somewhat minimal. Of course, one could always call the Java libraries from Scheme.
I'd be interested to hear about any experiences with using the above languages (or other lisps for that matter) on Android. Thanks!

Is C++ suitable for Android development?

For example, I want to create a simple application based on GPS, with making waypoints, showing them on map, etc.. So, is it possible to make such an app using C++ only, without any Java sources? Would it be more difficult than making the same on Java?
So, is it possible to make such an app using C++ only, without any
Java sources?
No. If you want to receive GPS coordinates, there is no way to do this without any Java code.
You could write an app in which Java is used as a thin wrapper around native code, using JNI to exchange data between Java and C++. However...
Would it be more difficult than making the same on Java?
Yes! In addition, the app would likely end up being:
Slower.
Buggier.
Harder to understand and maintain.
For Android development, Java is just the natural, normal, default language, and C++ is for exotic special tasks, typically those which involve really intensive calculations. You use it when you need it, not because you don't "want to" write in Java or because "Java is slow".
Writing correct JNI code is also not exactly trivial. For example, it's very easy to get local references and global references wrong if you don't read the documentation, as the compiler cannot detect their incorrect usage.
As the official documentation of the Android Native Development Kit says:
Before downloading the NDK, you should understand that the NDK will
not benefit most apps. As a developer, you need to balance its
benefits against its drawbacks. Notably, using native code on Android
generally does not result in a noticable performance improvement, but
it always increases your app complexity. In general, you should only
use the NDK if it is essential to your app—never because you simply
prefer to program in C/C++.
It also says:
You cannot access features such as Services and Content Providers
natively, so if you want to use them or any other framework API, you
can still write JNI code to do so.
Yes, search for Android NDK. Apparently it's a bit of a hassle, you'll be using SO a lot!

Safe string functions for native android development?

I was wondering - how 'safe' are the functions provided by android libraries when doing development of other native libraries on android?
Are there things like Microsoft's strsafe.h or bstring? Or can those be ported over?
There are usually safe variants of unsafe functions you can use to ensure any manipulation problems are generally detected and dealt with before introducing difficult to detect bugs only noticed later on in execution. If I understand your question correctly, you may want to look at things like snprintf in place of printf, strncat instead of strcat, and using variants of malloc when creating character arrays that follow the 'succeed or die' convention.
I find these references helpful when coding in C for Android (I know the native library is lacking a bit).
http://www.cplusplus.com/reference/clibrary/cstring/
http://en.wikipedia.org/wiki/C_string_handling#Overview_of_functions
Using variants that require additional information, such as max buffer size or trigger easy to spot errors on failure is generally helpful to avoid subtle bugs that can be a hassle later on.

Cross Mobile Options

I created an Android app. While creating one specific app was an interesting challenge, I'm now looking into creating a group of similar apps.
I'd like to create a group of similar Android apps and then move on to creating the same on tablets and iOS... (anything mobile).
I've considered doing so with a product called PhoneGap or doing a web based mobile app. Both of these options seem less than ideal. Doing the Android app I've been frustrated by Java's lack of control and low level constructs. Moving to something like a web based app seems like the exact wrong direction.
C++ is my language of choice. It has the ability to work at a low level, is highly portable across platforms, and has significant support for generic coding which would be useful for generating a group of similar apps. However, the Android documentation suggests to not use C++ unless your goal is porting existing code or dealing with computationally heavy tasks.
I'm leaning towards using C++ anyway, but are there other options I've not considered?
Thanks
You could in theory write your logic in C++ and then have UI layers on top that make use of it. If you are really comfortable with C++ that might be the way to go.
Almost any other parts (networking, UI, animation, etc) are better off being done in the native language of the platform. Use of cross platform solutions always limits you in some way, and usually leads to an application that is not as good as it could be for any platform.
Well, Google's recommendation to not use C++ is based on the following, I believe. C++ is low level, so you can get extra performance out of it if you know what you are doing. Google makes the reasonable assumption that many programmers do not. It is easier for an inexperienced programmer to do harm in C++ then to get a performance boost.
But, if you know what you are doing, it can help you. UI elements on both iOS and Android are implemented in their main language (obj-c, and Java respectively) so there is not a great way around that, but you can write core logic and other functions in C++ and it will be portable between them (iOS can use C++ directly and Android can use it via the Native Development Kit).
There are a few other options available. The one I ended up using is Appcelerator Titanium but please stay away from it. If your project gets complicated or large at all you will hate yourself for choosing it, as I did. Another interesting one that uses C++ instead of Javascript is Marmalade. I haven't used it though, so I can't comment on it.
A non-free solution that I hear good things about is Xamarin, who have ported both environments to C# and a .NET using Mono. However, you still have to write two versions of your code for the UI as far as I can tell.

Categories

Resources