python 开发android APP 简单小结

参考https://blog.csdn.net/qq_19582693/article/details/100598710

一、kivy安装

环境:python3.6、centos7.4

官网下载安装:https://kivy.org/#download 

官网教程pdf:链接:https://pan.baidu.com/s/1TRvn034FJ2O1oi_qA2d22w  提取码:olbj

以linux为例,https://kivy.org/doc/stable/installation/installation-linux.html

更新 pip,setuptools,virtualenv
python -m pip install --upgrade --user pip setuptools virtualenv
激活虚拟环境(可选)
python -m virtualenv ~/kivy_venv
source ~/kivy_venv/bin/activate

安装依赖(教程这么写的)
python -m pip install docutils pygmentspypiwin32 kivy.deps.sdl2 kivy.deps.glew
kivy.deps.gstreamer --extra-index-url https://kivy.org/downloads/packages/simple/

安装kivy
python -m pip install kivy
python -m pip install kivy_examples

python -m pip install ffpyplayer
在运行应用程序之前,请确保设置KIVY_VIDEO = ffpyplayer env变量。仅支持Python 3.5+。

二、 测试hello world

按教程,新建py文件测试。

代码如下:

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput


class LoginScreen(GridLayout):
    def __init__(self, **kwargs):
        super(LoginScreen, self).__init__(**kwargs)
        self.cols = 2
        self.add_widget(Label(text='User Name'))
        self.username = TextInput(multiline=False)
        self.add_widget(self.username)
        self.add_widget(Label(text='password'))
        self.password = TextInput(password=True, multiline=False)
        self.add_widget(self.password)


class UsernameApp(App):
    def build(self):
        return LoginScreen()


if __name__ == '__main__':
    UsernameApp().run()

三、打包app

https://kivy.org/doc/stable/guide/packaging-android.html

1、Buildozer方式

安装Buildozer:https://github.com/kivy/buildozer.git

git clone https://github.com/kivy/buildozer.git
cd buildozer
sudo python setup.py install

进入项目目录,初始化 Buildozer

buildozer init

会生成buildozer.spec文件,buildozer.spec 配置参数详解:https://buildozer.readthedocs.io/en/latest/specifications.html

至少修改这三项
# (str) Title of your applicationtitle = helloworld
# (str) Package namepackage.name = helloapp
# (str) Package domain (needed for android/ios packaging)package.domain = youer.com

安装buildozer的依赖项:https://buildozer.readthedocs.io/en/latest/installation.html#targeting-android

首先,使用以下命令安装buildozer项目:

pip3 install --user --upgrade buildozer

Android在Ubuntu 20.04(64bit)上
(预期在以后的版本中也能正常工作,但仅在最新的LTS中进行定期测试)

sudo apt update
sudo apt install -y git zip unzip openjdk-8-jdk python3-pip autoconf libtool pkg-config zlib1g-dev libncurses5-dev libncursesw5-dev libtinfo5 cmake libffi-dev libssl-dev
pip3 install --user --upgrade Cython==0.29.19 virtualenv  # the --user should be removed if you do this in a venv

# add the following line at the end of your ~/.bashrc file
export PATH=$PATH:~/.local/bin/

启动调试版本:在bin 目录中有一个APK文件。

buildozer -v android debug

或者,在设备上构建,推送和自动运行apk。

buildozer android debug deploy run

2、python-for-android 

3、kivy Launcher

 

 

你可能感兴趣的:(python,android)