You say, our future
Being loaded into a coffin, it can’t be dyed with dust
I have long wanted to develop an app to play with, but I am not familiar with java. I have not developed the experience of the app before, so I have been delayed. I recently thought of trying to develop an app in python. After searching for it, I found that there is a way to find it. Now I have some relatively mature modules, so I started to get started. I found that there are many pits in the process. In the end, I relied on Google to solve it, so I remembered it a little.
Although the python language is very versatile, it is a bit wrong to use it to develop the app. Therefore, the app developed with python should be used as a coding exercise or self-entertainment. In addition, the current module is not very mature. More, in short, advise the gentleman to sneak into.
Using python to develop an app requires a module of python –kivy, an open source, cross-platform Python development framework for developing and using innovative applications. program. In short, this is a python desktop development framework (similar to wxpython and other modules), the powerful is kivy support linux, mac, windows, android, ios platform, which is why the development of the app needs to use this module.
Although kivy is cross-platform, but you want to use python code on different platforms, you also need to package the python code into the executable program of the corresponding platform. Fortunately, there is a package tool project under the kivy project–buildozer, this is the official recommended packaging tool, because it is relatively simple, highly automated, other projects such as: [python-for-android] (https://github.com/kivy/ Python-for-android can also play a similar role, not introduced here.
Need to install the kivy development environment on the pc, here demonstrates the installation process under mac and linux.
Install some dependencies:
Install cython and kivy:
If you install kivy error, install kivy in the following way:
Note: If the kivy module is imported without error, the installation is successful.
Install dependencies first:
Install cython and kivy:
Centos install kivy reference: https://kivy.org/docs/installation/installation-linux.html#using-software-packages
Description: Other installation kivy mode can be moved: https://kivy.org/#download (requires over the wall)
After installing kivy, you can develop the app. Here, the hello-world program is demonstrated. The more complicated usage of kivy is not the focus of this article.
1) Create a main.py file and write:
2) Create a hello.kv file and write:
Brief description: main.py is the entry function, defines a HelloApp class, the class inherits kivy.app; the hello.kv file is a kivy program, which is equivalent to defining the interface style, etc. The file naming convention is lowercase the class name and removes the app.
Through the above coding, I created my first python app, which can run directly on mac, linux, windows, so how to make it run on Android or Apple? We know that running on Android, you need to package it into apk installer, so you need to use the buildozer tool mentioned above, (buildozer tool can package kivy program, support android, ios, etc.), buildozer installation process is relatively simple :
Run in the python project directory:
Successful operation will create a configuration file buildozer.spec, you can change the name of the app by modifying the configuration file, etc., then run:
Running the above command will generate a cross-platform installation package for Android, iOS, etc. If used for Android, use [python-for-android] (https://github.com/kivy/python-for-android )project.
When you run the above command for the first time, you will automatically download the necessary files such as Android sdk in the system, as shown below. (The process needs to be over the wall, and there are a lot of dependencies to download)
Note: This is only a demonstration of packaging into apk files, the iso platform can be studied by itself, reference documentation: https://github.com/kivy/buildozer.
If the above steps are all successful, an apk file should be generated in the bin directory under the project directory, similar to the following:
Then download the apk to the Android phone and install it. The test results are as follows:
Open the app:
###Buildozer pits in the packaging process
If you encounter an error during the packaging process, you can modify the log_level in the buildozer.spec configuration file to 2, and then re-run, you can see the specific error message.
This mistake is the fault I reported when running on centos7. The effect is that the system lacks some 32-bit dependent files.
The error is that the cython file is faulty. It may be that the cython module is not installed, or the version is faulty.
This is the last step in the packaging, copy the apk file to the project bin directory time error, is a bug in buildozer.
Modify the /usr/local/lib/python2.7/dist-packages/buildozer/tagets/android.py file:
(1) Import at the beginning of the file:
(2) Replace the code below line 786: XXX found how the apk name is really built from the title:
Kivy officially launched a buildozer virtual machine image, installed buildozer and some dependent files to provide a platform for buildozer package testing. Since I used the buildozer package on the mac to report an error, I changed it to centos and it still didn’t succeed. So I downloaded this virtual machine and the test results are as follows:
Virtual machine download address: http://txzone.net/files/torrents/kivy-buildozer-vm-2.0.zip
Note: For those who can’t solve the dependency problem, you can use this virtual machine to package the program. The development environment still recommends your own machine.
Because the focus of this article is on how to develop a python app using kivy+buildozer, the kivy development process and app functionality are simplified. To learn how to develop more complex apps, please refer to: https://muxuezi.github.io/posts/kivy-perface.html#
~! ~ Toss python makes me happy, …, think about it or go back and learn java~! ~