Buildozer构建的应用崩溃:jnius.jnius.JavaException 未找到指定类问题求助
Hey there! Let's break down what's happening and get your app running again.
First, let's clarify what jnius is: it's a Python library that acts as a bridge between your Python/Kivy code and Android's native Java system. It lets your app interact with Android-specific features (like sensors, permissions, or the app lifecycle) and is critical for launching your Buildozer-built app properly.
The error you're seeing (java.lang.ClassNotFoundException: org.renpy.android.PythonActivity) means the Android system can't locate the default activity class that Buildozer/Kivy uses to start your app. This is almost always a configuration issue or a problem with stale build cache. Here's how to fix it:
Step 1: Verify Your Buildozer Spec Configuration
Open your buildozer.spec file and check these key settings:
android.activity_class: Ensure this is set toorg.renpy.android.PythonActivity(this is the default, but accidental edits can break things—revert it if you changed it).android.api: Stick to a stable API level (29 or 30 work great for most apps). Avoid the absolute latest API unless you specifically need it, as newer versions can introduce compatibility quirks.requirements: Make surejniusandkivyare listed (e.g.,requirements = python3,kivy,jnius). Buildozer usually adds these automatically, but double-check if you modified this section manually.
Step 2: Clean Build Cache and Rebuild
Old cached build files often cause weird class-not-found errors. Run these commands in your project directory:
buildozer android clean buildozer android debug deploy run
The clean command wipes out stale artifacts, and the second command rebuilds your app from scratch with fresh, correct files.
Step 3: Check SDK/NDK Compatibility
If you manually set android.sdk or android.ndk versions in your spec, ensure they're compatible with your Kivy/Buildozer version. For example, Buildozer v1.4.0 works well with NDK r25c and SDK API 33. If you're unsure, comment out these lines in the spec—Buildozer will automatically download and use compatible versions.
Step 4: Rule Out Custom Activity Conflicts
If you tried to implement a custom Android Activity class, make sure:
- Your custom activity extends
org.renpy.android.PythonActivityin its Java code. - You updated
android.activity_classin the spec to point to your custom class (e.g.,com.yourdomain.yourapp.CustomActivity). - The class is properly included in your build (add your custom Java module path to
android.add_srcin the spec if needed).
If you didn't intend to use a custom activity, just revert to the default org.renpy.android.PythonActivity setting.
Your Logcat Error for Reference
02-19 15:47:11.942 21537 21624 I python : File "jnius/jnius_export_func.pxi", line 26, in jnius.jnius.find_javaclass 02-19 15:47:11.944 21537 21624 I python : File "jnius/jnius_utils.pxi", line 91, in jnius.jnius.check_exception 02-19 15:47:11.945 21537 21624 I python : jnius.jnius.JavaException: JVM exception occurred: Didn't find class "org.renpy.android.PythonActivity" on path: DexPathList[[zip file "/data/app/me.mitja.testi-bLnHXylo6xtj-klSnNJ1dw==/base.apk"],nativeLibraryDirectories=[/data/app/me.mitja.testi-bLnHXylo6xtj-klSnNJ1dw==/lib/arm, /data/app/me.mitja.testi-bLnHXylo6xtj-klSnNJ1dw==/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib, /product/lib]] java.lang.ClassNotFoundException
Start with cleaning the cache and verifying the spec settings—those are the most common fixes. Let me know if you hit more roadblocks!
内容的提问来源于stack exchange,提问作者Mitja

