如何在python中完全制作Android应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49955489/
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
How to make Android app completely in python?
提问by Ivo
I would like to develop a (rather simple) android app to be distributed via Play Store. I would like to do so completely in python. However, the online research hasn't quite enlightened me: most comments are either outdated (>1 year old, and I feel there might be better integration of python since then) or they talk about running pythonin android (e.g. here).
我想开发一个(相当简单的)Android 应用程序以通过 Play 商店分发。我想完全在python中这样做。然而,在线研究并没有让我很受启发:大多数评论要么已经过时(> 1 年,我觉得从那时起可能会有更好的 python 集成)或者他们谈论在 android 中运行 python(例如here)。
Therefore, I'm looking for information regarding the questions:
因此,我正在寻找有关问题的信息:
- is it feasible to develop an App completely in python - and what are the tools to do so? (Is e.g. Kivy recommendable?)
- if so: what are the best software environments to implement this? (I unsuccessfully tried using Android Studio but couldn't figure out a way to run python code there.)
- 完全用python开发应用程序是否可行 - 有哪些工具可以做到?(例如 Kivy 值得推荐吗?)
- 如果是这样:实现这一点的最佳软件环境是什么?(我尝试使用 Android Studio 失败,但找不到在那里运行 python 代码的方法。)
I'm quite new to app development and would highly appreciate any leads of doing this in python rather than in Jave etc., which I don't know yet.
我对应用程序开发很陌生,并且非常感谢在 python 中而不是在 Jave 等中执行此操作的任何线索,我还不知道。
Many thanks for you help in advance.
非常感谢您提前提供帮助。
采纳答案by maroof shittu
To answer your first question: yes it is feasible to develop an android application in pure python, in order to achieve this I suggest you use BeeWare, which is just a suite of python tools, that work together very well and they enable you to develop platform native applications in python.
回答你的第一个问题:是的,用纯 python 开发一个 android 应用程序是可行的,为了实现这一点,我建议你使用BeeWare,它只是一套 python 工具,它们可以很好地协同工作,使你能够开发python中的平台本机应用程序。
checkout this videoby the creator of BeeWare that perfectly explains and demonstrates it's application
结帐BeeWare 创建者的这个视频,它完美地解释和演示了它的应用程序
How it works
这个怎么运作
Android's preferred language of implementation is Java - so if you want to write an Android application in Python, you need to have a way to run your Python code on a Java Virtual Machine. This is what VOCdoes. VOCis a transpiler - it takes Python source code, compiles it to CPython Bytecode, and then transpiles that bytecode into Java-compatible bytecode. The end result is that your Python source code files are compiled directly to a Java .class file, which can be packaged into an Android application.
Android 的首选实现语言是 Java - 所以如果你想用 Python 编写一个 Android 应用程序,你需要有一种在 Java 虚拟机上运行你的 Python 代码的方法。这就是VOC 的作用。VOC是一个转译器——它采用 Python 源代码,将其编译为 CPython 字节码,然后将该字节码转译为与 Java 兼容的字节码。最终结果是您的 Python 源代码文件被直接编译为 Java .class 文件,该文件可以打包到 Android 应用程序中。
VOC also allows you to access native Java objects as if they were Python objects, implement Java interfaces with Python classes, and subclass Java classes with Python classes. Using this, you can write an Android application directly against the native Android APIs.
VOC 还允许您像访问 Python 对象一样访问本机 Java 对象,使用 Python 类实现 Java 接口,并使用 Python 类对 Java 类进行子类化。使用它,您可以直接针对原生 Android API 编写 Android 应用程序。
Once you've written your native Android application, you can use Briefcaseto package your Python code as an Android application.
编写本机 Android 应用程序后,您可以使用公文包将 Python 代码打包为 Android 应用程序。
Briefcaseis a tool for converting a Python project into a standalone native application. You can package projects for:
公文包是一种将 Python 项目转换为独立本机应用程序的工具。您可以为以下项目打包项目:
- Mac
- Windows
- Linux
- iPhone/iPad
- Android
- AppleTV
- tvOS.
- 苹果电脑
- 视窗
- Linux
- iPhone/iPad
- 安卓
- 苹果电视
- 电视操作系统。
You can check This native Android Tic Tac Toe appwritten in Python, using the BeeWare suite. on GitHub
您可以使用 BeeWare 套件检查这个用 Python 编写的原生 Android Tic Tac Toe 应用程序。在 GitHub 上
in addition to the BeeWare tools, you'll need to have a JDK and Android SDK installed to test run your application.
除了 BeeWare 工具之外,您还需要安装 JDK 和 Android SDK 来测试运行您的应用程序。
and to answer your second question: a good environment can be anything you are comfortable with be it a text editor and a command line, or an IDE, if you're looking for a good python IDE I would suggest you try Pycharm, it has a community edition which is free, and it has a similar environment as android studio, due to to the fact that were made by the same company.
并回答你的第二个问题:一个好的环境可以是你喜欢的任何东西,无论是文本编辑器和命令行,还是 IDE,如果你正在寻找一个好的 python IDE,我建议你尝试Pycharm,它有一个免费的社区版,由于是同一家公司制作的,因此它的环境与android studio相似。
I hope this has been helpful
我希望这是有帮助的
回答by E. Gordon
You could try BeeWare- as described on their website:
您可以尝试BeeWare- 如他们网站上所述:
Write your apps in Python and release them on iOS, Android, Windows, MacOS, Linux, Web, and tvOS using rich, native user interfaces. One codebase. Multiple apps.
使用 Python 编写您的应用程序,并使用丰富的本机用户界面在 iOS、Android、Windows、MacOS、Linux、Web 和 tvOS 上发布它们。一个代码库。多个应用程序。
Gives you want you want now to write Android Apps in Python, plus has the advantage that you won't need to learn yet another framework in future if you end up also wanting to do something on one of the other listed platforms.
满足您现在想要用 Python 编写 Android 应用程序的需求,而且如果您最终还想在其他列出的平台之一上做某事,那么您将来无需再学习另一个框架。
Here's the Tutorial for Android Apps.
这是Android 应用程序的教程。
回答by harvey
There are two primary contenders for python apps on Android
Android 上的 Python 应用程序有两个主要竞争者
Chaquopy
查科比
This integrates with the Android build system, it provides a Python API for all android features. To quote the site "The complete Android API and user interface toolkit are directly at your disposal."
这与 Android 构建系统集成,它为所有 android 功能提供了一个 Python API。引用该网站的话“您可以直接使用完整的 Android API 和用户界面工具包。”
Beeware (Toga widget toolkit)
Beeware(Toga 小部件工具包)
This provides a multi target transpiler, supports many targets such as Android and iOS. It uses a generic widget toolkit (toga) that maps to the host interface calls.
这提供了一个多目标转译器,支持许多目标,例如 Android 和 iOS。它使用映射到主机接口调用的通用小部件工具包 (toga)。
Which One?
哪一个?
Both are active projects and their github accounts shows a fair amount of recent activity.
两者都是活跃的项目,他们的 github 帐户显示了相当多的近期活动。
Beeware Toga like all widget libraries is good for getting the basics out to multiple platforms. If you have basic designs, and a desire to expand to other platforms this should work out well for you.
Beeware Toga 与所有小部件库一样,非常适合将基础知识应用到多个平台。如果您有基本的设计,并且希望扩展到其他平台,那么这应该很适合您。
On the other hand, Chaquopy is a much more precise in its mapping of the python API to Android. It also allows you to mix in Java, useful if you want to use existing code from other resources. If you have strict design targets, and predominantly want to target Android this is a much better resource.
另一方面,Chaquopy 在将 Python API 映射到 Android 方面要精确得多。它还允许您混合使用 Java,如果您想使用其他资源中的现有代码,这将非常有用。如果您有严格的设计目标,并且主要针对 Android,这是一个更好的资源。
回答by Bertram Gilfoyle
Android, Python !
安卓,Python!
When I saw these two keywords together in your question, Kivyis the one which came to my mind first.
当我在你的问题中看到这两个关键词时,首先想到的是Kivy。
Before coming to native Android development in Java using Android Studio, I had tried Kivy. It just awesome. Here are a few advantage I could find out.
在使用 Android Studio 使用 Java 进行原生 Android 开发之前,我曾尝试过Kivy。太棒了。以下是我可以找到的一些优势。
Simple to use
使用简单
With a python basics, you won't have trouble learning it.
有了 Python 基础知识,您就可以轻松学习它。
Good community
好社区
It's well documented and has a great, active community.
它有据可查,并拥有一个伟大而活跃的社区。
Cross platform.
跨平台。
You can develop thing for Android, iOS, Windows, Linux and even Raspberry Pi with this single framework. Open source.
你可以使用这个单一的框架为 Android、iOS、Windows、Linux 甚至 Raspberry Pi 开发东西。开源。
It is a free software
这是一个免费软件
At least few of it's (Cross platform) competitors want you to pay a fee if you want a commercial license.
如果您想要商业许可,至少有少数(跨平台)竞争对手希望您支付费用。
Accelerated graphics support
加速图形支持
Kivy's graphics engine build over OpenGL ES 2 makes it suitable for softwares which require fast graphics rendering such as games.
Kivy 基于OpenGL ES 2 构建的图形引擎使其适用于需要快速图形渲染的软件,例如游戏。
Now coming into the next part of question, you can't use Android Studio IDE for Kivy. Hereis a detailed guide for setting up the development environment.
现在进入问题的下一部分,您不能将 Android Studio IDE 用于 Kivy。这是设置开发环境的详细指南。