| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [View Raw Code] [Original HTTPS Page] |
Basic steps to build and run an Android project generated by pn.
pn run android unpacks the bundled Android template into build/android/android_template and copies your app/ into the template's app/src/main/python/app/. The template is two Gradle modules: app/ (the thin Kotlin host: MainActivity, Chaquopy setup, the PythonHost callback) and pythonnative/ (the native rendering core: component managers, gesture recognizers, animations, and native modules, with no Chaquopy dependency). Native plugins from [plugins].paths and installed packages are copied into the pythonnative/ module before Gradle runs.
No network is required for the template itself; the template zip is bundled with the package. [requirements].packages are written to the staged project's requirements.txt and installed by Chaquopy during the Gradle build, once per ABI in [android].abi_filters, from PyPI, Chaquopy's own wheel index, and any [requirements].extra_index_urls. Run pn deps android first to preview what will resolve; see PyPI packages.
Your app/ directory contains @pn.component function components. The native Android template boots Python with pythonnative.bootstrap.start() and asks the Host native module to mount your root component inside a ScreenFragment (a thin subclass of the runtime's PNScreenFragment). You don't call anything for this; just export your component and configure the entry point in pythonnative.toml (app.entry_point).
pn run androidWith several devices or emulators connected, list them and target one:
pn devices android
pn run android --device emulator-5554Or to only prepare the project without building:
pn run android --prepare-onlyThis will stage files under build/android/android_template so you can open it in Android Studio if you prefer.
After the app is installed and launched, pn run android tails adb logcat and streams it back to your terminal. The filter is scoped to the tags Chaquopy and the template use, so you get Python output without the usual logcat noise:
| Tag | Source |
|---|---|
| python.stdout | print() / anything written to sys.stdout |
| python.stderr | tracebacks / anything written to sys.stderr |
| PythonNative | Kotlin host and runtime (bridge, component managers, modules) |
| AndroidRuntime:E | Fatal Java/Kotlin exceptions |
Press Ctrl+C to stop streaming. Pass --no-logs to skip log streaming entirely (useful in CI or when you'd rather watch logs from Android Studio). To re-attach later without rebuilding, run pn logs android.
If you need unfiltered output, run adb logcat yourself in another terminal.
Remove the build directory safely:
pn cleanSee Troubleshooting for the most common errors and their fixes.
| Back | FazBrowse Home | New Git URL |