Repository navigation
Description
Checklist
- [ x] the issue is indeed a bug and not a support request
- [ x] issue doesn't already exist: https://github.com/kivy/python-for-android/issues
- I have a short, runnable example that reproduces the issue
- [ x] I reproduced the problem with the latest development version (
p4a.branch = develop) - [ x] I used the grave accent (aka backticks) to format code or logs when appropriated
Versions
- Python: 3.9.9
- OS: WSL/Android
- Kivy: 2.1.0
- Cython:
- OpenJDK: 13
Description
The p4a service_class_name option allows changing the service base class name, enabling a custom service class implementation. The implementation of the option is here:
One of the required methods in this class is run() which in the default implementation calls nativeStart(). https://github.com/kivy/python-for-android/blob/develop/pythonforandroid/bootstraps/common/build/src/main/java/org/kivy/android/PythonService.java#L178-L187
However nativeStart() is a JNI method hard coded with the default base class name https://github.com/kivy/python-for-android/blob/develop/pythonforandroid/bootstraps/common/build/jni/application/src/start.c#L359.
So if a custom service base class is used to start a service, we get a run time link error. Because java_org_kivy_android_CustomPythonService_nativeStart() does not exist. See buildozer.spec and log snippets below, where we use the option to replace PythonService with CustomPythonService which has unchanged functionality.
The feature was added here 49de421
buildozer.spec
Command:
buildozer android debugSpec file:
# (str) Full name including package path of the Java class that implements Python Service
# use that parameter to set custom Java class instead of PythonService
android.service_class_name = org.kivy.android.CustomPythonService
# (list) List of Java files to add to the android project (can be java or a
# directory containing the files)
android.add_src =org/kivy/android/CustomPythonService.java
Logs
09-27 16:28:23.517 9923 9944 E AndroidRuntime: java.lang.UnsatisfiedLinkError: No implementation found for void org.kivy.android.CustomPythonService.nativeStart(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) (tried Java_org_kivy_android_CustomPythonService_nativeStart and Java_org_kivy_android_CustomPythonService_nativeStart__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2)
Activity
RobertFlatt commentedon Sep 28, 2022
My error the CustomPythonService should inherit from PythonService, and not replace it.
Though perhaps the text in buildozer.spec "instead of PythonService" is less than clear.