从 Android 开始:Java 或 Python (SL4A)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3346970/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Starting with Android: Java or Python (SL4A)
提问by Mad Scientist
I just ordered an Android smartphone and want to start playing around with creating my own applications. Now the question is which language to use, the native Java or Python using SL4A (former ASE).
我刚订购了一部 Android 智能手机,想开始尝试创建自己的应用程序。现在的问题是使用哪种语言,使用 SL4A(前身为 ASE)的原生 Java 或 Python。
I tend to Python, as I know it much better than Java, but I'm wondering what I would be missing using a "second class" language on Android. On the SL4A website it is also stated to be alpha quality software, which is not exactly encouraging.
我倾向于 Python,因为我比 Java 更了解它,但我想知道在 Android 上使用“二等”语言会错过什么。在 SL4A 网站上,它也被称为 alpha 质量软件,这并不完全令人鼓舞。
I'm also not quite sure what the limitations of the scripting environment are and if they would be problematic.
我也不太确定脚本环境的限制是什么,以及它们是否会出现问题。
回答by Dave Kirby
At the moment you cannot create a releasable program with Python (or any other scripting language) using SL4A. I have heard rumours that this is something Google is working on, but even if they do enable it Python apps are likely to be slow and power-hungry compared to Java. Also the scripting API only gives you access to a limited subset of the native Java API. I would not consider using SL4A for serious development work at the moment, only for one-off scripts and prototyping.
目前,您无法使用 SL4A 使用 Python(或任何其他脚本语言)创建可发布的程序。我听说有传言说这是谷歌正在做的事情,但即使他们启用了它,与 Java 相比,Python 应用程序可能会很慢且耗电。此外,脚本 API 仅允许您访问本地 Java API 的有限子集。目前我不会考虑将 SL4A 用于严肃的开发工作,仅用于一次性脚本和原型设计。
Take a look at Scala. It is a statically typed language on the JVM, but uses type inference to remove most of the noise that you get in Java. It also fully supports functional programming, and has a lot of pythonish features. Because it is statically typed it is as efficient as straight Java with none of the disadvantages. IMHO it is the language that Java should have been in the first place.
看看Scala。它是 JVM 上的静态类型语言,但使用类型推断来消除您在 Java 中遇到的大部分噪音。它还完全支持函数式编程,并具有很多pythonish 特性。因为它是静态类型的,所以它和直接的 Java 一样高效,没有任何缺点。恕我直言,Java 本来就应该是这种语言。
A lot of people are blogging about using Scala on Android, so Google around for more information.
很多人都在写关于在 Android 上使用 Scala 的博客,所以谷歌搜索更多信息。
回答by Pentium10
More likely will depend what type of applications you will develop.
更有可能取决于您将开发什么类型的应用程序。
I would start with Java to become familiar with Android SDK. Anyway first you need to look into some examples, tutorials. Most of them are done in Java, and only a few, probably on the dev site of SL4A for that.
我会从 Java 开始熟悉 Android SDK。无论如何,首先您需要查看一些示例、教程。其中大部分是用 Java 完成的,只有少数可能在 SL4A 的开发站点上。
Also there is native development Android NDK, that can be programmed with C++.
还有原生开发的Android NDK,可以用C++编程。
But anyway Java rules for general applications.
但无论如何,Java 规则适用于一般应用程序。
回答by Christopher Mahan
Adding an update to Dave Kirby's answer:
为 Dave Kirby 的回答添加更新:
Issue 55, Distribute scripts as APKs, in the issue tracker at SL4A deals specifically with that.
问题 55,将脚本作为 APK 分发,在 SL4A 的问题跟踪器中专门处理了这个问题。
There is a solution being worked out (may be complete by now) described at SharingScripts. The only issue seems to be that you need to have a interpreter APK already installed.
在SharingScripts 中描述了一个正在制定的解决方案(现在可能已经完成)。唯一的问题似乎是您需要已经安装了解释器 APK。
回答by bodman
you may want to check out Rubotoit is a framework for developing Android apps based on JRuby which means your JRuby code can call Android APIs and can also be called back from the Android Java side. Hereis an introduction article .
您可能想查看Ruboto,它是一个基于 JRuby 开发 Android 应用程序的框架,这意味着您的 JRuby 代码可以调用 Android API,也可以从 Android Java 端回调。 这是一篇介绍文章。
回答by Kriattiffer
Consider ising Kivy, if you want to write Android apps with Python. The process of packing script to .apk file is described here.
如果您想使用 Python 编写 Android 应用程序,请考虑使用Kivy。这里描述了将脚本打包成.apk 文件的过程。
The problem is, resulting .apk will be big (~7Mb for 300Kb data). It is obvious, because you need to pack there Python runtime and all libraries.
问题是,生成的 .apk 会很大(300Kb 数据约为 7Mb)。很明显,因为您需要打包 Python 运行时和所有库。
Another solution I have heard of, is Pygame for Android, but it works on lower lewel, so you need to draw graphics manually.
我听说过的另一个解决方案是Pygame for Android,但它适用于较低的 lewel,因此您需要手动绘制图形。
Unfortunately, I have not tried any of this ways yet, but it looks, that I'm going to start using kivy soon.
不幸的是,我还没有尝试过任何这样的方法,但看起来我很快就会开始使用 kivy。

