如何用python完全制作Android应用程序?[关闭]

问题:如何用python完全制作Android应用程序?[关闭]

我想开发一个(相当简单)的Android应用程序,可通过Play商店进行分发。我想在python中完全这样做。但是,在线研究并没有启发我:大多数评论要么已经过时(> 1岁,并且我认为从那时起可能会更好地集成python),要么他们谈论在android中运行python(例如here)。

因此,我正在寻找有关以下问题的信息:

  • 用python完全开发App是否可行-这样做的工具是什么?(例如,推荐Kivy吗?)
  • 如果是这样:最佳软件环境是什么?(我尝试使用Android Studio失败,但是找不到在其中运行python代码的方法。)

我对应用程序开发非常陌生,非常感谢在python中而不是在Jave等中进行此操作的所有线索,我尚不知道。

非常感谢您的提前帮助。

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 python in android (e.g. 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.)

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.

Many thanks for you help in advance.


回答 0

回答您的第一个问题:是的,用纯python开发一个android应用程序是可行的,为了实现这一目标,我建议您使用BeeWare,它只是一套python工具,可以很好地协同工作,使您能够开发python中的平台本机应用程序。

结帐这个视频由BeeWare的创造者,完美解释并演示了它的应用

这个怎么运作

Android的首选实现语言是Java-因此,如果您想用Python编写Android应用程序,则需要一种在Java虚拟机上运行Python代码的方法。这就是VOC所做的。VOC是一个编译器-它获取Python源代码,将其编译为CPython字节码,然后将该字节码转换为与Java兼容的字节码。最终结果是将您的Python源代码文件直接编译为Java .class文件,然后可以将其打包到Android应用程序中。

VOC还允许您像访问Python对象一样访问本机Java对象,使用Python类实现Java接口,以及使用Python类实现Java类的子类。使用此功能,您可以直接针对本机Android API编写Android应用程序。

编写本机Android应用程序后,您可以使用“ 公文包”将Python代码打包为Android应用程序。

公文包是用于将Python项目转换为独立的本机应用程序的工具。您可以将项目打包为:

  • 苹果电脑
  • 视窗
  • 的Linux
  • iPhone / iPad
  • 安卓系统
  • 苹果电视
  • 电视操作系统。

您可以使用BeeWare套件检查用Python编写的本机Android Tic Tac Toe应用程序。在GitHub上

除BeeWare工具外,您还需要安装JDK和Android SDK来测试您的应用程序的运行。

并回答您的第二个问题:好的环境可以是任何您喜欢的东西,无论是文本编辑器,命令行还是IDE,如果您正在寻找好的python IDE,我建议您尝试Pycharm,它具有一个免费的社区版本,由于它是同一家公司生产的,因此它的环境与android studio类似。

我希望这是有帮助的

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.

checkout this video by the creator of BeeWare that perfectly explains and demonstrates it’s application

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 VOC does. VOC is 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.

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.

Once you’ve written your native Android application, you can use Briefcase to package your Python code as an Android application.

Briefcase is a tool for converting a Python project into a standalone native application. You can package projects for:

  • Mac
  • Windows
  • Linux
  • iPhone/iPad
  • Android
  • AppleTV
  • tvOS.

You can check This native Android Tic Tac Toe app written in Python, using the BeeWare suite. on GitHub

in addition to the BeeWare tools, you’ll need to have a JDK and Android SDK installed to test run your application.

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.

I hope this has been helpful


回答 1

您可以尝试BeeWare-如其网站上所述:

使用Python编写应用程序,然后使用丰富的本机用户界面在iOS,Android,Windows,MacOS,Linux,Web和tvOS上发布它们。一个代码库。多个应用程序。

提供您想要现在就用Python编写Android Apps的优点,并且具有以下优点:如果您最终也想在其他列出的平台上做某事,则将来无需学习其他框架。

这是Android Apps教程

You could try BeeWare – as described on their website:

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.

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.

Here’s the Tutorial for Android Apps.


回答 2

Android上有两个主要的python应用程序竞争者

Chaquopy

https://chaquo.com/chaquopy/

它与Android构建系统集成,为所有android功能提供了Python API。引用网站“完整的Android API和用户界面工具包直接供您使用”。

Beeware(Toga小部件工具包)

https://pybee.org/

这提供了一个多目标编译器,支持许多目标,例如Android和iOS。它使用映射到主机接口调用的通用窗口小部件工具箱(toga)。

哪一个?

两者都是活跃项目,它们的github帐户显示了大量近期活动。

像所有小部件库一样,Beeware Toga也非常适合将基础知识扩展到多个平台。如果您具有基本的设计,并且希望扩展到其他平台,那么这应该对您来说很好。

另一方面,Chaquopy在将python API映射到Android方面更加精确。它还允许您混合使用Java,如果要使用其他资源中的现有代码,则很有用。如果您有严格的设计目标,并且主要想针对Android,那么这是一个更好的资源。

There are two primary contenders for python apps on Android

Chaquopy

https://chaquo.com/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.”

Beeware (Toga widget toolkit)

https://pybee.org/

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.

Which One?

Both are active projects and their github accounts shows a fair amount of recent activity.

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.

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.


回答 3

Android,Python!

当我在您的问题中同时看到这两个关键字时,我最先想到的是Kivy

在使用Android Studio进行Java原生Android开发之前,我曾尝试过Kivy。太棒了。这是我可以发现的一些优点。


使用简单

有了python基础知识,您就可以轻松学习它。


良好的社区

它有据可查,拥有一个活跃的社区。


跨平台。

您可以使用此单一框架为Android,iOS,Windows,Linux甚至Raspberry Pi开发东西。开源。


它是一个免费软件

如果您想要商业许可证,那么至少(跨平台)竞争者都希望您付费。


加速图形支持

Kivy的图形引擎基于OpenGL ES 2构建,使其适用于需要快速图形渲染的软件,例如游戏。



现在进入问题的下一部分,您不能将Android Studio IDE用于Kivy。是设置开发环境的详细指南。

Android, Python !

When I saw these two keywords together in your question, Kivy is the one which came to my mind first.

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.


Simple to use

With a python basics, you won’t have trouble learning it.


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.


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.



Now coming into the next part of question, you can’t use Android Studio IDE for Kivy. Here is a detailed guide for setting up the development environment.