|
| 1 | +Getting Started |
| 2 | +=============== |
| 3 | + |
| 4 | +Getting up and running on Python for android is a simple process and should only take you a couple of minutes. We'll refer to Python for android as P4A in this documentation. |
| 5 | + |
| 6 | +Concepts |
| 7 | +-------- |
| 8 | + |
| 9 | +- requirements: For P4A, your applications dependencies are requirements that looks like `requirements.txt`, in one difference: P4A will search a recipe first instead of installing requirements with pip. |
| 10 | + |
| 11 | +- recipe: A recipe is a file that define how to compile a requirement. Any libraries that have a Python Extension MUST have a recipe in P4A. If there is no recipe for a requirement, it will be downloaded using pip. |
| 12 | + |
| 13 | +- build: A build is referring to a compiled recipe. |
| 14 | + |
| 15 | +- distribution: A distribution is the final "build" of all your requirements |
| 16 | + |
| 17 | +- bootstrap: A bootstrap is a "base" that will "boot" your application. Your application could boot on a project that use SDL2 as a base, or pygame, or a pure python web. The bootstrap you're using might behave differently. |
| 18 | + |
| 19 | + |
| 20 | +Installation |
| 21 | +------------ |
| 22 | + |
| 23 | +Installing P4A |
| 24 | +~~~~~~~~~~~~~~ |
| 25 | + |
| 26 | +P4A is not yet released on Pypi. Therefore, you can install it using pip:: |
| 27 | + |
| 28 | + pip install git+https://github.com/kivy/python-for-android.git |
| 29 | + |
| 30 | +Installing Dependencies |
| 31 | +~~~~~~~~~~~~~~~~~~~~~~~ |
| 32 | + |
| 33 | +P4A has severals dependencies that must be installed: |
| 34 | + |
| 35 | +- git |
| 36 | +- ant |
| 37 | +- python2 |
| 38 | +- cython (can be installed via pip) |
| 39 | +- a Java JDK (e.g. openjdk-7) |
| 40 | +- zlib (including 32 bit) |
| 41 | +- libncurses (including 32 bit) |
| 42 | +- unzip |
| 43 | +- virtualenv (can be installed via pip) |
| 44 | +- ccache (optional) |
| 45 | + |
| 46 | +On recent versions of Ubuntu and its derivatives you may be able to |
| 47 | +install most of these with:: |
| 48 | + |
| 49 | + sudo dpkg --add-architecture i386 |
| 50 | + sudo apt-get update |
| 51 | + sudo apt-get install -y build-essential ccache git zlib1g-dev python2.7 python2.7-dev libncurses5:i386 libstdc++6:i386 zlib1g:i386 openjdk-7-jdk unzip ant ccache |
| 52 | + |
| 53 | +Installing Android SDK |
| 54 | +~~~~~~~~~~~~~~~~~~~~~~ |
| 55 | + |
| 56 | +You need to download and unpack to a directory (let's say $HOME/Documents/): |
| 57 | + |
| 58 | +- `Android SDK <https://developer.android.com/sdk/index.html#Other>`_ |
| 59 | +- `Android NDK <https://developer.android.com/ndk/downloads/index.html>`_ |
| 60 | + |
| 61 | +Then, you can edit your `~/.bashrc` or others favorite shell to include new environment variables necessary for building on android:: |
| 62 | + |
| 63 | + # Adjust the paths! |
| 64 | + export ANDROIDSDK="$HOME/Documents/android-sdk-21" |
| 65 | + export ANDROIDNDK="$HOME/Documents/android-ndk-r10e" |
| 66 | + export ANDROIDAPI="14" # Minimum API version your application require |
| 67 | + export ANDROIDNDKVER="r10e" # Version of the NDK you installed |
| 68 | + |
| 69 | +You have the possibility to configure on any command the PATH to the SDK, NDK and Android API using: |
| 70 | + |
| 71 | +- `--sdk_dir PATH` as an equivalent of `$ANDROIDSDK` |
| 72 | +- `--ndk_dir PATH` as an equivalent of `$ANDROIDNDK` |
| 73 | +- `--android_api VERSION` as an equivalent of `$ANDROIDAPI` |
| 74 | +- `--ndk_ver PATH` as an equivalent of `$ANDROIDNDKVER` |
| 75 | + |
| 76 | + |
| 77 | +Usage |
| 78 | +----- |
| 79 | + |
| 80 | +Build a Kivy application |
| 81 | +~~~~~~~~~~~~~~~~~~~~~~~~ |
| 82 | + |
| 83 | +To build your application, you need to have a name, version, a package identifier, and explicitly write the bootstrap you want to use, as long as the requirements:: |
| 84 | + |
| 85 | + p4a apk --private $HOME/code/myapp --package=org.example.myapp --name "My application" --version 0.1 --bootstrap=sdl2 --requirements=python2,kivy |
| 86 | + |
| 87 | +This will first build a distribution that contains `python2` and `kivy`, and using a SDL2 bootstrap. Python2 is here explicitely written as kivy can work with python2 or python3. |
| 88 | + |
| 89 | +Build a vispy application |
| 90 | +~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 91 | + |
| 92 | +To build your application, you need to have a name, version, a package identifier, and explicitly write the bootstrap you want to use, as long as the requirements:: |
| 93 | + |
| 94 | + p4a apk --private $HOME/code/myapp --package=org.example.myapp --name "My Vispy Application" --version 0.1 --bootstrap=sdl2 --requirements=vispy |
| 95 | + |
| 96 | +Rebuild everything |
| 97 | +~~~~~~~~~~~~~~~~~~ |
| 98 | + |
| 99 | +In case you messed up somewhere, one day, or having issue, you might want to clean all the downloads, build, distributions available. This can be done with:: |
| 100 | + |
| 101 | + p4a clean_all |
| 102 | + |
| 103 | + |
| 104 | +Advanced usage |
| 105 | +-------------- |
| 106 | + |
| 107 | +Recipes management |
| 108 | +~~~~~~~~~~~~~~~~~~ |
| 109 | + |
| 110 | +You can see the list of the available recipes with:: |
| 111 | + |
| 112 | + p4a recipes |
| 113 | + |
| 114 | +In case you are contributing to p4a, if you want to test a recipes again, |
| 115 | +you need to clean the build and rebuild your distribution:: |
| 116 | + |
| 117 | + p4a clean_recipe_build RECIPENAME |
| 118 | + p4a clean_dists |
| 119 | + # then rebuild your distribution |
| 120 | + |
| 121 | +You can write "private" recipes for your application, just create a `p4a-folder` into your application, and put a recipe in it (edit the `__init__.py`):: |
| 122 | + |
| 123 | + mkdir -p p4a-recipes/myrecipe |
| 124 | + touch p4a-recipes/myrecipe/__init__.py |
| 125 | + |
| 126 | + |
| 127 | +Distributions management |
| 128 | +~~~~~~~~~~~~~~~~~~~~~~~~ |
| 129 | + |
| 130 | +Every APK you build will create a distribution depending the requirements you put on the command line, until you specify a distribution name:: |
| 131 | + |
| 132 | + p4a apk --dist_name=myproject ... |
| 133 | + |
| 134 | +This will ensure your distribution will be built always in the same directory, and prevent having your disk growing everytime you adjust a requirement. |
| 135 | + |
| 136 | +You can list the available distribution:: |
| 137 | + |
| 138 | + p4a distributions |
| 139 | + |
| 140 | +And clean all of them:: |
| 141 | + |
| 142 | + p4a clean_dists |
| 143 | + |
| 144 | +Going further |
| 145 | +------------- |
| 146 | + |
| 147 | +P4A is capable of a lot like: |
| 148 | + |
| 149 | +- Using a configuration file to prevent you typing all the options everytime |
| 150 | +- ... |
0 commit comments