Manage dependencies and re-lock¶
Your app's dependencies live in [project].dependencies. kivyforge resolves them
separately for each target and pins the result in that target's lockfile. This
page shows how to add a dependency, hold a package on one version, re-lock, and
keep the lock in sync with pyproject.toml.
Before you begin¶
- A project with an overlay for each target you build. See Project configuration.
- A host that can build the target.
lockfollows the same host rules asbuild: lock iOS and macOS on a Mac, Windows on Windows, and Linux on x86_64 Linux. Android locks on any of them. See Which host builds which target. - For an Android project that declares Maven dependencies in
[tool.kivy.android.gradle], a JDK.lockruns Gradle to resolve them.
Add or change a dependency¶
-
Edit
[project].dependenciesinpyproject.toml:[project] dependencies = [ "kivy>=2.3.1", "pillow>=10", ] -
Re-lock each target you build:
kivyforge lock -p macos kivyforge lock -p android
Each target gets its own pylock.<platform>.toml, because the wheels differ by
platform.
Pin a package version¶
The first lock takes the newest version your specifier allows. After that,
kivyforge lock keeps the versions already locked: when a lock input
changes, only the packages that change requires move. --update resolves
everything to the newest version allowed.
To hold a package on one version, require that version exactly:
[project]
dependencies = [
"kivy==2.3.1",
"pillow==10.4.0",
]
A range such as kivy>=2.3.1 or pillow>=10 moves to the newest match the
next time you pass --update. A Kivy 3 development snapshot is a pre-release, so the
specifier has to name one. See the kivy_generation setting in
Configure your Android app. A range such as
kivy>=3.0.0.dev0,<4 still moves to the newest snapshot. Pin the snapshot
you mean:
[project]
dependencies = [
"kivy==3.0.0.dev202607301604",
]
--update also moves packages you did not list. On Android, lock adds pyjnius
when you have not declared it, using a range, so --update picks up newer
pyjnius releases. Declare it yourself to choose the version. See
Call Android APIs with pyjnius. A package pulled in by
another package moves the same way. List it in [project].dependencies with
== and that requirement is the one lock resolves.
lock --check resolves again, keeping the locked versions, and compares the
result with the lock on disk, so a new upstream release alone doesn't fail it.
The next lock overwrites a hand-edited pylock.<platform>.toml. Change the
specifier and re-lock.
When a step edits pyproject.toml after the lock was resolved, and this build
should keep the pins on disk, pass --no-verify-lock to build or package.
That skips the drift check. See
Drive kivyforge from CI or an agent.
Make sure every dependency has a wheel¶
kivyforge installs prebuilt wheels only and never builds a package from source.
A pure-Python package works on every target. A package with compiled code works
only on targets that have a matching wheel: macosx_*, manylinux_*,
win_amd64, ios_*, or android_*. If a target has no matching wheel, lock
fails for that target. See
Prebuilt runtimes and wheels.
To add an index, list it in the target overlay's extra_index_urls. When two
indexes offer the same version of a package, the one listed first wins. See
Where packages come from.
Use your own wheels¶
When you build a wheel yourself, for example a patched Kivy, put it in a
directory in your project and list that directory in find_links. A package
with a wheel there comes only from there, even when an index publishes a newer
version.
- Copy the wheels into a directory inside your project, such as
wheels/. Include one wheel for each architecture or ABI you lock. -
List the directory in the target's overlay:
[tool.kivy.android] find_links = ["wheels"] -
Re-lock the target:
kivyforge lock -p android
The lock records each local wheel with a project-relative path and its
SHA-256. Commit the wheels with the lock, because build installs from that
path. When you replace a locked wheel, even with one of the same filename, the
next lock resolves that package again and leaves the others as they are.
To use a package from GitHub that isn't released on PyPI, build its wheel with pip and add it the same way. See Build a wheel from a GitHub repository. To test your app with your own build of Kivy, see Package your app with a Kivy development build.
If the directory has a wheel for a package on one ABI but not another, lock
fails with KF-LOCK-SOURCE-UNAVAILABLE and names the missing ABI. It does not
take that ABI's wheel from an index.
To take the package from an index again, pin it to that index, as the next
section shows, or remove its wheels from the directory, and re-lock. A pin
leaves your wheels where they are, so removing the pin switches back.
lock --update alone does not switch: it picks newer versions within a
package's source, and never changes the source.
Choose the index a package comes from¶
When several indexes publish the same package, pin it to the one you want. A
pinned package comes only from that index, and an index you mark explicit
supplies only the packages pinned to it, so it cannot replace anything else.
-
Declare the index in
[tool.kivy], giving it a name:[[tool.kivy.index]] name = "mobile-wheels" url = "https://elliotgarbus.github.io/kivy-mobile-wheels/simple/" explicit = true -
Pin the package to it, for every target in
[tool.kivy.sources], or for one target in that target's ownsourcestable:[tool.kivy.android.sources] kivy = { index = "mobile-wheels" } -
Re-lock the target:
kivyforge lock -p android
pypi is a built-in index name, so pyjnius = { index = "pypi" } holds a
package to PyPI without declaring anything.
The lock records each package's index in its index field, so you can check
where a package came from in pylock.<platform>.toml. If the pinned index has
no wheel for one of your targets, lock fails with
KF-LOCK-SOURCE-UNAVAILABLE instead of taking it from another index.
For every key and rule, see the
[tool.kivy] reference.
Switch between your own wheel and an index¶
A pin outranks find_links, so you can keep a patched wheel in your project
and still choose, package by package, where to take it from:
- With the wheel in
find_linksand no pin,lockuses your wheel, even after--update. - To take the index's release instead, for example once it includes your
fix, pin the package to the index and re-lock.
lockwarns that it is ignoring your wheel. - To go back to your wheel, remove the pin and re-lock.
Prune unused Kivy dependencies¶
Kivy's wheels declare dependencies that many apps don't use. To leave them out of
the lock and the bundle, list them in the overlay's exclude key:
[tool.kivy.macos]
exclude = ["kivy-garden", "docutils", "pygments"]
Keep the lock in sync¶
The lock records a hash of its lock inputs: [project].dependencies,
requires-python, and the target's Python version, architectures, indexes,
find_links, exclude, and native libraries. When you change one of them,
re-lock the targets you build. The re-lock keeps the versions already locked
and moves only what the change requires. Editing anything else, such as
signing, icons, or another platform's settings, leaves the lock in sync.
If the lock is in sync, lock leaves it unchanged. To resolve again anyway and
take the newest version each specifier allows, pass --update:
kivyforge lock -p linux --update
Refresh downloaded artifacts¶
To download the pinned runtime and native artifacts again without resolving
again, run upgrade:
kivyforge upgrade -p linux
To remove the generated project files and also clear the download cache, run:
kivyforge clean --cache
This clears kivyforge's cache of runtimes and wheels. pip's own cache, which
lock uses while resolving, is separate; clear it with pip cache purge.
Verify¶
Check that the lock matches pyproject.toml:
kivyforge lock -p linux --check
The command exits 0 and prints that the lock is up to date. It resolves
while keeping the locked versions, so a newer upstream release alone does not
fail it. If a lock input changed, it lists what would change, exits 4 with
KF-LOCK-DRIFT, and writes nothing. build, run, and package fail the
same way when the lock inputs' hash no longer matches the lock. See
Pin a package version and
Drive kivyforge from CI or an agent.