Additionally you would need few system dependencies and configuration.
Xcode 10 or above, with an iOS SDK and command line tools installed:
xcode-select --install
Using brew, you can install the following dependencies:
brew install autoconf automake libtool pkg-config
brew link libtool
Using the toolchain
Any Python extensions or C/C++ library must be compiled: you need to have what
we call a recipe to compile it. For example, Python, libffi, SDL2, SDL_image,
freetype... all the dependencies, compilation and packaging instructions are
contained in a recipe.
You can list the available recipes and their versions with:
You can build recipes at the same time by adding them as parameters:
$ toolchain build python3 openssl kivy
Recipe builds can be removed via the clean command e.g.:
$ toolchain clean openssl
You can install package that don't require compilation with pip::
$ toolchain pip install plyer
The Kivy recipe depends on several others, like the sdl* and python recipes.
These may in turn depend on others e.g. sdl2_ttf depends on freetype, etc.
You can think of it as follows: the kivy recipe will compile everything
necessary for a minimal working version of Kivy.
Don't grab a coffee, just do diner. Compiling all the libraries for the first
time, 2x over (remember, 2 archs, x86_64, arm64) will take time.
For a complete list of available commands, type:
$ toolchain
Create the Xcode project
The toolchain.py can create the initial Xcode project for you::
Your app directory must contain a main.py. A directory named <title>-ios
will be created, with an Xcode project in it.
You can open the Xcode project using::
$ open touchtracer-ios/touchtracer.xcodeproj
Then click on Play, and enjoy.
Did you know ?
Everytime you press Play, your application directory will be synced to
the <title>-ios/YourApp directory. Don't make changes in the -ios
directory directly.
Configuring your App
You can configure and customize your app in various ways:
Set the icon and launch images in XCode. Note that XCode requires that you
specify these assests per device or/and iOS version.
When you first build your XCode project, a 'main.m' file is created in your
XCode project folder. This file configures your environment variables and
controls your application startup. You can edit this file to customize your
launch environment.
Kivy uses SDL, and as soon as the application starts the SDL main, the launch
image will disappear. To prevent that, you need to have 2 files named
Default.png and Default-Landscape.png, and put them
in the Resources folder in Xcode (not in your application folder)
Did you know ?
If you wish to restrict your apps orientation, you should do this via
the 'export_orientation' function in 'main.m'. The XCode orientation
settings should be set to support all.
Using recipes
Recipes are used to install and compile any libraries you may need to use. These
recipes follow the same format as those used by the
Python-for-Android sister project.
Please refer to the
recipe documentation
there for more detail.
Reducing the application size
If you would like to reduce the size of your distributed app, there are a few
things you can do to achieve this:
Minimize the build/pythonX/lib/pythonXX.zip: this contains all the python
modules. You can edit the zip file and remove all the files you'll not use
(reduce encodings, remove xml, email...)
Go to the settings panel > build, search for "strip" options, and
triple-check that they are all set to NO. Stripping does not work with
Python dynamic modules and will remove needed symbols.
By default, the iOS package compiles binaries for all processor
architectures, namely x86_64 and arm64 as per the guidelines from
Apple. You can reduce the size of your ipa significantly by removing the
x86_64 architecture as they are used only for the emulator.
The procedure is to first compile/build all the host recipes as is:
toolchain build hostpython3
Then build all the rest of the recipes using --arch=arm64
arguments as follows:
toolchain build python3 kivy --arch=arm64
Note that these packages will not run in the iOS emulators, so use them
only for deployment.
Usage
toolchain <command> [<args>]
Available commands:
build Build a recipe (compile a library for the required target
architecture)
clean Clean the build of the specified recipe
distclean Clean the build and the result
recipes List all the available recipes
status List all the recipes and their build status
Xcode:
create Create a new xcode project
update Update an existing xcode project (frameworks, libraries..)
launchimage Create Launch images for your xcode project
icon Create Icons for your xcode project
pip Install a pip dependency into the distribution
pip3 Install a pip dependency into the python 3 distribution
Development
Alternatively, it's also possible to clone the repository and use all the
described commands in the above sections.
Clone and install it to your local virtual environment:
You need to install the Command line tools: xcode-select --install
Error: SDK "iphonesimulator" cannot be located
Xcode path is not set up correctly. Run the following command to fix this: sudo xcode-select --switch <YOUR_XCODEAPP_PATH> (Change <YOUR_XCODEAPP_PATH> to the path that reflects your XCode installation, usually is /Applications/Xcode.app)
Bitcode is partially supported now (Xcode setting ENABLE_BITCODE can be set to Yes).
Supported recipes: python3, kivy, sdl2, sdl2_image, sdl2_mixer and libffi
You don't have permissions to run
It is due to invalid archs, search for them and check it. Maybe you
targetted a simulator but have only arm64. Maybe you want to target
your iPad but it as only x86_64.
Why does the python multiprocess/subprocess module not work?
The iOS application model does not currently support multi-processing in a
cross-platform compatible way. The application design focuses on minimizing
processor usage (to minimize power consumption) and promotes an
alternative concurrency model.
If you need to make use of multiple processes, you should consider using
PyObjus to leverage native iOS
functionals for this.
Support
If you need assistance, you can ask for help on our mailing list:
请发表评论