build android web view app by python (python-for-android)

last modified : 2017-05-29 | published: 2017-05-29 | category:

Environment

Installing p4a

sudo pip install git+https://github.com/kivy/python-for-android.git

Installing Dependencies

sudo apt-get update
sudo apt-get install -y build-essential git zlib1g-dev python2.7 python2.7-dev libncurses5:i386 libstdc++6:i386 zlib1g:i386 openjdk-8-jdk unzip ant ccache
sudo pip install virtualenv 
sudo pip install cython

Installing Android SDK

android-sdk-23 android-ndk-r12b

edit ~/.bashrc,add at end

export ANDROIDSDK="$HOME/android-sdk-23"
export ANDROIDNDK="$HOME/android-ndk-r12b"
export ANDROIDAPI="19"
export ANDROIDNDKVER="r12b"

Flask Demo

create ~/code/myapp/main.py

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

if __name__ == '__main__':
    app.run(port=32145)

project path is ~/code/myapp

main.py file with the python script to be run

Build APK

p4a apk --private $HOME/code/myapp --package=org.example.myapp --name "App Name" --version 0.1 --bootstrap=webview --requirements=flask --port=32145 --arch=armeabi-v7a

Link

https://python-for-android.readthedocs.io/en/latest/quickstart/#installation