-
Notifications
You must be signed in to change notification settings - Fork 24
Configuring Kivy p4a on macOS
Feodor Fitsner edited this page Oct 27, 2023
·
9 revisions
Install Android Studio.
Android SDK will be located at $HOME/Library/Android/sdk
.
Install Temurin8:
brew install --cask temurin8
export JAVA_HOME=/Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home
Set the following environment variables:
export ANDROID_SDK_ROOT="$HOME/Library/Android/sdk"
export NDK_VERSION=25.2.9519653
export SDK_VERSION=android-33
Add path to sdkmanager
to PATH
:
export PATH=$ANDROID_SDK_ROOT/tools/bin:$PATH
Install Android SDK and NDK from https://developer.android.com/ndk/downloads/ or with Android SDK Manager:
echo "y" | sdkmanager --install "ndk;$NDK_VERSION" --channel=3
echo "y" | sdkmanager --install "platforms;$SDK_VERSION"
Create new Python virtual environment:
python3 -m venv .venv
source .venv/bin/activate
Install p4a:
pip install python-for-android
Install Cython:
pip install --upgrade cython
Run p4a with --requirements
including your custom Python libraries, like numpy
in the following example:
p4a create --requirements numpy --arch arm64-v8a --arch armeabi-v7a --arch x86_64 --sdk-dir $ANDROID_SDK_ROOT --ndk-dir $ANDROID_SDK_ROOT/ndk/$NDK_VERSION --dist-name serious_python
Choose No to "Do you want automatically install prerequisite JDK? [y/N]".
When p4a
command completes a Python distributive with your custom libraries will be located at:
$HOME/.python-for-android/dists/serious_python
Location of hostpython3
:
~/.python-for-android/build/other_builds/hostpython3/desktop/hostpython3/native-build/python3
.so
files:
~/.python-for-android/dists/serious_python/libs
Header files:
~/.python-for-android/build/other_builds/python3/arm64-v8a__ndk_target_21/python3/Include
Python packages:
~/.python-for-android/dists/serious_python/_python_bundle__arm64-v8a/_python_bundle
Installing pip
on hostpython3
:
~/.python-for-android/build/other_builds/hostpython3/desktop/hostpython3/native-build/python3 -m ensurepip
export JAVA_HOME=/Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home
p4a aab --private $HOME/projects/samples/kivy_android/service_app --package org.example.myapp --name "My App" --version 0.1 --bootstrap sdl2 --requirements python3,kivy --arch arm64-v8a --arch armeabi-v7a --release --sdk-dir $HOME/Library/Android/sdk --ndk-dir $HOME/Library/Android/sdk/ndk/25.2.9519653
export JAVA_HOME=""
cd ~/.python-for-android/dists/unnamed_dist_1
./gradlew clean bundleRelease