You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在虚拟环境中启动新Kivy项目时重复下载依赖求助

Fixing Repeated SDK/NDK Downloads for New Kivy Projects in Virtual Environments

Hey there, I’ve dealt with this exact frustrating issue before—having to wait for SDK/NDK downloads every time you start a new Kivy project in a fresh virtual environment is a huge waste of time. Let’s walk through actionable solutions to stop this from happening:

1. Set Global Environment Variables for SDK/NDK

Kivy’s build tools (like Buildozer) check for system-wide environment variables first before downloading dependencies. Here’s how to set them:

  • On Linux/macOS: Add these lines to your shell config file (.bashrc, .zshrc, or .profile), or directly in your virtual environment’s activate script to keep it isolated:
    export ANDROID_SDK_ROOT="/path/to/your/pre-downloaded/sdk"
    export ANDROID_NDK_ROOT="/path/to/your/pre-downloaded/ndk"
    export ANDROID_BUILD_TOOLS_VERSION="33.0.2" # Use the version Kivy requires
    
  • On Windows: Open System Properties → Advanced → Environment Variables, add new system/user variables with the same keys and paths to your pre-downloaded SDK/NDK.

Once set, any new Kivy project (even in a fresh virtual env) will use these existing paths instead of downloading everything again.

2. Configure Buildozer’s Global Settings

Buildozer uses a per-project buildozer.spec by default, but you can create a global config to apply settings across all projects:

  1. Create a global config file at ~/.buildozer/config (Linux/macOS) or %USERPROFILE%\.buildozer\config (Windows).
  2. Add these lines to the file, replacing paths with your existing SDK/NDK locations:
    [app]
    android.sdk_path = /path/to/your/sdk
    android.ndk_path = /path/to/your/ndk
    android.build_tools_version = 33.0.2
    

Now every new Buildozer project you initialize will inherit these settings, skipping the download step.

3. Reuse a Preconfigured Base Virtual Environment

Instead of creating a new virtual environment from scratch every time:

  1. Create a base virtual environment, install Kivy, and configure all the SDK/NDK paths as above.
  2. For new projects, either:
    • Clone the base environment (use cp -r /path/to/base/env /path/to/new/env on Linux/macOS, or copy the folder on Windows), then activate it and install any project-specific dependencies.
    • Export the base environment’s dependencies to a requirements.txt with pip freeze > requirements.txt, then create a new env and run pip install -r requirements.txt—just make sure the SDK/NDK environment variables are set in the new env too.

4. Manually Pre-Download Dependencies

If you haven’t already downloaded the SDK/NDK:

  1. Grab the compatible versions (check Kivy’s docs for exact NDK/SDK versions required for your Kivy version—e.g., Kivy 2.2.0 often uses NDK r25b and SDK API level 33).
  2. Download the Android SDK Command Line Tools, extract it to a fixed directory, then run sdkmanager to install required platform tools and build tools.
  3. Download the matching NDK version, extract it to a fixed directory.
  4. Point your environment variables or Buildozer config to these paths as outlined in steps 1 and 2.

Pro Tip

Always double-check that the SDK/NDK versions match what your Kivy version expects—using an incompatible version can lead to build errors, even if you skip the download.

内容的提问来源于stack exchange,提问作者John Albert

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 09:23:41