i have tried many solutions and followed many guides but i cant get it to work i have a minimal code example here.
this is my main.py:
JavaScript
x
55
55
1
import kivy
2
import platform
3
from kivy.app import App
4
from kivy.uix.label import Label
5
from kivy.uix.button import Button
6
7
from multiprocessing.dummy import Process
8
from kivy.uix.widget import Widget
9
import jnius
10
from kivy.clock import Clock
11
from kivy.uix.image import Image
12
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
13
14
15
16
class fscreen(Widget):
17
def __init__(self, **kwargs):
18
super().__init__(**kwargs)
19
20
21
class theapp(App):
22
def build(self):
23
self.cnt = 0
24
self.screenm = ScreenManager() #(transition=FadeTransition())
25
self.fscreen = fscreen()
26
screen = Screen(name = "first screen")
27
screen.add_widget(self.fscreen)
28
self.screenm.add_widget(screen)
29
return self.screenm
30
31
def change(self, *args):
32
self.cnt += 1
33
self.fscreen.ids.lb.text = str(self.cnt) + ' hello '
34
print(str(self.cnt) + ' hello ')
35
def label_update(self):
36
Clock.schedule_interval(self.change, 1)
37
38
def on_start(self):
39
from kivy import platform
40
if platform == "android":
41
self.start_service()
42
Process(target=self.label_update).start()
43
44
@staticmethod
45
def start_service():
46
from jnius import autoclass
47
service = autoclass("org.pck.ser.Serviceser")
48
mActivity = autoclass("org.kivy.android.PythonActivity").mActivity
49
service.start(mActivity, "")
50
return service
51
52
if __name__ == "__main__":
53
theapp = theapp()
54
theapp.run()
55
this is a my kv file:
JavaScript
1
7
1
<fscreen>
2
Label:
3
id:lb
4
size: root.width*0.1, root.height*0.05
5
pos: root.width*0.45,root.height*0.3
6
7
and this is my service.py same folder as main.py:
JavaScript
1
13
13
1
import kivy
2
from kivy.app import App
3
from kivy.uix.screenmanager import ScreenManager, Screen
4
from kivy.uix.widget import Widget
5
from jnius import autoclass
6
7
PythonService = autoclass('org.kivy.android.PythonService')
8
PythonService.mService.setAutoRestartService(True)
9
10
while True:
11
print('hello')
12
time.sleep(1)
13
this is the buildozer.spec
JavaScript
1
17
17
1
[app]
2
3
# (str) Title of your application
4
title = ser
5
6
# (str) Package name
7
package.name = ser
8
9
# (str) Package domain (needed for android/ios packaging)
10
package.domain = org.pck
11
12
# (str) Source code where the main.py live
13
source.dir = .
14
15
requirements = python3,kivy==2.0.0,kivymd==0.104.2,numpy,pillow,kivy_garden.mapview,requests,charset_normalizer,chardet,idna, urllib3,certifi,plyer==2.0.0,sqlite3,pickle-mixin,kivygradient,jnius,android
16
services = ser:service.py
17
and i have this output from buildozer android debug deploy run logcat i have cleaned modified versions and did a lot of things but same thing i dont know what i am missing
JavaScript
1
13
13
1
04-16 02:42:04.993 18517 18610 I python : Traceback (most recent call last):
2
04-16 02:42:04.994 18517 18610 I python : File "/home/odr/Desktop/dev/MobileApps/foreground_test/.buildozer/android/app/main.py", line 57, in <module>
3
04-16 02:42:04.994 18517 18610 I python : File "/home/odr/Desktop/dev/MobileApps/foreground_test/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/ser/armeabi-v7a/kivy/app.py", line 949, in run
4
04-16 02:42:04.995 18517 18610 I python : File "/home/odr/Desktop/dev/MobileApps/foreground_test/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/ser/armeabi-v7a/kivy/app.py", line 944, in _run_prepare
5
04-16 02:42:04.995 18517 18610 I python : File "kivy/_event.pyx", line 709, in kivy._event.EventDispatcher.dispatch
6
04-16 02:42:04.995 18517 18610 I python : File "/home/odr/Desktop/dev/MobileApps/foreground_test/.buildozer/android/app/main.py", line 44, in on_start
7
04-16 02:42:04.996 18517 18610 I python : File "/home/odr/Desktop/dev/MobileApps/foreground_test/.buildozer/android/app/main.py", line 50, in start_service
8
04-16 02:42:04.996 18517 18610 I python : File "/home/odr/Desktop/dev/MobileApps/foreground_test/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/ser/armeabi-v7a/jnius/reflect.py", line 229, in autoclass
9
04-16 02:42:04.996 18517 18610 I python : File "jnius/jnius_export_func.pxi", line 26, in jnius.jnius.find_javaclass
10
04-16 02:42:04.997 18517 18610 I python : File "jnius/jnius_utils.pxi", line 91, in jnius.jnius.check_exception
11
04-16 02:42:04.997 18517 18610 I python : jnius.jnius.JavaException: JVM exception occurred: Didn't find class "org.pck.ser.Serviceser" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/org.pck.ser-KtQcSSOANf-UBQoqXEY3dA==/base.apk"],nativeLibraryDirectories=[/data/app/org.pck.ser-KtQcSSOANf-UBQoqXEY3dA==/lib/arm, /data/app/org.pck.ser-KtQcSSOANf-UBQoqXEY3dA==/base.apk!/lib/armeabi-v7a, /system/lib, /system/vendor/lib]] java.lang.ClassNotFoundException
12
04-16 02:42:04.997 18517 18610 I python : Python for android ended.
13
Advertisement
Answer
I fixed some lines and cleaned my buildozer:
this is the complete working version of my buildozer.spec:
JavaScript
1
333
333
1
[app]
2
3
# (str) Title of your application
4
title = ser
5
6
# (str) Package name
7
package.name = ser
8
9
# (str) Package domain (needed for android/ios packaging)
10
package.domain = org.pck
11
12
# (str) Source code where the main.py live
13
source.dir = .
14
15
# (list) Source files to include (let empty to include all the files)
16
source.include_exts = py,png,jpg,kv,atlas,db,ttf,wav
17
18
# (list) List of inclusions using pattern matching
19
source.include_patterns = cache/*.png,fonts/cello-sans/*.ttf,fonts/fondation/*.ttf
20
21
# (list) Source files to exclude (let empty to not exclude anything)
22
#source.exclude_exts = spec
23
24
# (list) List of directory to exclude (let empty to not exclude anything)
25
#source.exclude_dirs = tests, bin
26
27
# (list) List of exclusions using pattern matching
28
#source.exclude_patterns = license,images/*/*.jpg
29
30
# (str) Application versioning (method 1)
31
version = 0.1
32
33
# (str) Application versioning (method 2)
34
# version.regex = __version__ = ['"](.*)['"]
35
# version.filename = %(source.dir)s/main.py
36
37
# (list) Application requirements
38
# comma separated e.g. requirements = sqlite3,kivy
39
#requirements = python3,Kivy-Garden==0.1.1,futures==2.1.6,requests==1.2.3,certifi,urllib3,chardet,idna
40
#requirements = python3,kivy==2.0.0,kivymd==0.104.2,numpy,pillow,kivy_garden.mapview,requests,charset_normalizer,chardet,idna, urllib3,certifi,plyer==2.0.0,sqlite3,pickle-mixin,kivygradient,jnius,android
41
requirements = python3,kivy==2.0.0,kivymd==0.104.2,numpy,pillow,kivy_garden.mapview,requests,charset_normalizer,chardet,idna, urllib3,certifi,plyer==2.0.0,sqlite3,pickle-mixin,kivygradient,android
42
43
# (str) Custom source folders for requirements
44
# Sets custom source for any requirements with recipes
45
# requirements.source.kivy = ../../kivy
46
47
# (list) Garden requirements
48
#garden_requirements = kivy.garden.mapview
49
50
# (str) Presplash of the application
51
#presplash.filename = presplash.png
52
53
# (str) Icon of the application
54
#icon.filename = icon.png
55
56
# (str) Supported orientation (one of landscape, sensorLandscape, portrait or all)
57
orientation = portrait
58
59
# (list) List of service to declare
60
#services = NAME:ENTRYPOINT_TO_PY,NAME2:ENTRYPOINT2_TO_PY
61
services = Worker:service.py
62
63
#
64
# OSX Specific
65
#
66
67
#
68
# author = © Copyright Info
69
70
# change the major version of python used by the app
71
osx.python_version = 3
72
73
# Kivy version to use
74
osx.kivy_version = 1.9.1
75
76
#
77
# Android specific
78
#
79
80
# (bool) Indicate if the application should be fullscreen or not
81
fullscreen = 0
82
83
# (string) Presplash background color (for new android toolchain)
84
# Supported formats are: #RRGGBB #AARRGGBB or one of the following names:
85
# red, blue, green, black, white, gray, cyan, magenta, yellow, lightgray,
86
# darkgray, grey, lightgrey, darkgrey, aqua, fuchsia, lime, maroon, navy,
87
# olive, purple, silver, teal.
88
#android.presplash_color = #FFFFFF
89
90
# (list) Permissions
91
android.permissions = INTERNET, READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE, ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION, FOREGROUND_SERVICE
92
93
# (int) Target Android API, should be as high as possible.
94
#android.api = 27
95
96
# (int) Minimum API your APK will support.
97
#android.minapi = 21
98
99
# (int) Android SDK version to use
100
#android.sdk = 20
101
102
# (str) Android NDK version to use
103
#android.ndk = 19b
104
105
# (int) Android NDK API to use. This is the minimum API your app will support, it should usually match android.minapi.
106
#android.ndk_api = 21
107
108
# (bool) Use --private data storage (True) or --dir public storage (False)
109
#android.private_storage = True
110
111
# (str) Android NDK directory (if empty, it will be automatically downloaded.)
112
#android.ndk_path =
113
114
# (str) Android SDK directory (if empty, it will be automatically downloaded.)
115
#android.sdk_path =
116
117
# (str) ANT directory (if empty, it will be automatically downloaded.)
118
#android.ant_path =
119
120
# (bool) If True, then skip trying to update the Android sdk
121
# This can be useful to avoid excess Internet downloads or save time
122
# when an update is due and you just want to test/build your package
123
# android.skip_update = False
124
125
# (bool) If True, then automatically accept SDK license
126
# agreements. This is intended for automation only. If set to False,
127
# the default, you will be shown the license when first running
128
# buildozer.
129
# android.accept_sdk_license = False
130
131
# (str) Android entry point, default is ok for Kivy-based app
132
#android.entrypoint = org.renpy.android.PythonActivity
133
134
# (str) Android app theme, default is ok for Kivy-based app
135
# android.apptheme = "@android:style/Theme.NoTitleBar"
136
137
# (list) Pattern to whitelist for the whole project
138
#android.whitelist =
139
140
# (str) Path to a custom whitelist file
141
#android.whitelist_src =
142
143
# (str) Path to a custom blacklist file
144
#android.blacklist_src =
145
146
# (list) List of Java .jar files to add to the libs so that pyjnius can access
147
# their classes. Don't add jars that you do not need, since extra jars can slow
148
# down the build process. Allows wildcards matching, for example:
149
# OUYA-ODK/libs/*.jar
150
#android.add_jars = foo.jar,bar.jar,path/to/more/*.jar
151
152
# (list) List of Java files to add to the android project (can be java or a
153
# directory containing the files)
154
#android.add_src =
155
156
# (list) Android AAR archives to add (currently works only with sdl2_gradle
157
# bootstrap)
158
#android.add_aars =
159
160
# (list) Gradle dependencies to add (currently works only with sdl2_gradle
161
# bootstrap)
162
#android.gradle_dependencies =
163
164
# (list) add java compile options
165
# this can for example be necessary when importing certain java libraries using the 'android.gradle_dependencies' option
166
# see https://developer.android.com/studio/write/java8-support for further information
167
# android.add_compile_options = "sourceCompatibility = 1.8", "targetCompatibility = 1.8"
168
169
# (list) Gradle repositories to add {can be necessary for some android.gradle_dependencies}
170
# please enclose in double quotes
171
# e.g. android.gradle_repositories = "maven { url 'https://kotlin.bintray.com/ktor' }"
172
#android.add_gradle_repositories =
173
174
# (list) packaging options to add
175
# see https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.PackagingOptions.html
176
# can be necessary to solve conflicts in gradle_dependencies
177
# please enclose in double quotes
178
# e.g. android.add_packaging_options = "exclude 'META-INF/common.kotlin_module'", "exclude 'META-INF/*.kotlin_module'"
179
#android.add_gradle_repositories =
180
181
# (list) Java classes to add as activities to the manifest.
182
#android.add_activities = com.example.ExampleActivity
183
184
# (str) OUYA Console category. Should be one of GAME or APP
185
# If you leave this blank, OUYA support will not be enabled
186
#android.ouya.category = GAME
187
188
# (str) Filename of OUYA Console icon. It must be a 732x412 png image.
189
#android.ouya.icon.filename = %(source.dir)s/data/ouya_icon.png
190
191
# (str) XML file to include as an intent filters in <activity> tag
192
#android.manifest.intent_filters =
193
194
# (str) launchMode to set for the main activity
195
#android.manifest.launch_mode = standard
196
197
# (list) Android additional libraries to copy into libs/armeabi
198
#android.add_libs_armeabi = libs/android/*.so
199
#android.add_libs_armeabi_v7a = libs/android-v7/*.so
200
#android.add_libs_arm64_v8a = libs/android-v8/*.so
201
#android.add_libs_x86 = libs/android-x86/*.so
202
#android.add_libs_mips = libs/android-mips/*.so
203
204
# (bool) Indicate whether the screen should stay on
205
# Don't forget to add the WAKE_LOCK permission if you set this to True
206
#android.wakelock = False
207
208
# (list) Android application meta-data to set (key=value format)
209
#android.meta_data =
210
211
# (list) Android library project to add (will be added in the
212
# project.properties automatically.)
213
#android.library_references =
214
215
# (list) Android shared libraries which will be added to AndroidManifest.xml using <uses-library> tag
216
#android.uses_library =
217
218
# (str) Android logcat filters to use
219
android.logcat_filters = *:S python:D
220
221
# (bool) Copy library instead of making a libpymodules.so
222
#android.copy_libs = 1
223
224
# (str) The Android arch to build for, choices: armeabi-v7a, arm64-v8a, x86, x86_64
225
android.arch = armeabi-v7a
226
227
# (int) overrides automatic versionCode computation (used in build.gradle)
228
# this is not the same as app version and should only be edited if you know what you're doing
229
# android.numeric_version = 1
230
231
#
232
# Python for android (p4a) specific
233
#
234
235
# (str) python-for-android fork to use, defaults to upstream (kivy)
236
#p4a.fork = kivy
237
238
# (str) python-for-android branch to use, defaults to master
239
#p4a.branch = master
240
241
# (str) python-for-android git clone directory (if empty, it will be automatically cloned from github)
242
#p4a.source_dir =
243
244
# (str) The directory in which python-for-android should look for your own build recipes (if any)
245
#p4a.local_recipes =
246
247
# (str) Filename to the hook for p4a
248
#p4a.hook =
249
250
# (str) Bootstrap to use for android builds
251
# p4a.bootstrap = sdl2
252
253
# (int) port number to specify an explicit --port= p4a argument (eg for bootstrap flask)
254
#p4a.port =
255
256
257
#
258
# iOS specific
259
#
260
261
# (str) Path to a custom kivy-ios folder
262
#ios.kivy_ios_dir = ../kivy-ios
263
# Alternately, specify the URL and branch of a git checkout:
264
ios.kivy_ios_url = https://github.com/kivy/kivy-ios
265
ios.kivy_ios_branch = master
266
267
# Another platform dependency: ios-deploy
268
# Uncomment to use a custom checkout
269
#ios.ios_deploy_dir = ../ios_deploy
270
# Or specify URL and branch
271
ios.ios_deploy_url = https://github.com/phonegap/ios-deploy
272
ios.ios_deploy_branch = 1.7.0
273
274
# (str) Name of the certificate to use for signing the debug version
275
# Get a list of available identities: buildozer ios list_identities
276
#ios.codesign.debug = "iPhone Developer: <lastname> <firstname> (<hexstring>)"
277
278
# (str) Name of the certificate to use for signing the release version
279
#ios.codesign.release = %(ios.codesign.debug)s
280
281
282
[buildozer]
283
284
# (int) Log level (0 = error only, 1 = info, 2 = debug (with command output))
285
log_level = 2
286
287
# (int) Display warning if buildozer is run as root (0 = False, 1 = True)
288
warn_on_root = 1
289
290
# (str) Path to build artifact storage, absolute or relative to spec file
291
# build_dir = ./.buildozer
292
293
# (str) Path to build output (i.e. .apk, .ipa) storage
294
# bin_dir = ./bin
295
296
# -----------------------------------------------------------------------------
297
# List as sections
298
#
299
# You can define all the "list" as [section:key].
300
# Each line will be considered as a option to the list.
301
# Let's take [app] / source.exclude_patterns.
302
# Instead of doing:
303
#
304
#[app]
305
#source.exclude_patterns = license,data/audio/*.wav,data/images/original/*
306
#
307
# This can be translated into:
308
#
309
#[app:source.exclude_patterns]
310
#license
311
#data/audio/*.wav
312
#data/images/original/*
313
#
314
315
316
# -----------------------------------------------------------------------------
317
# Profiles
318
#
319
# You can extend section / key with a profile
320
# For example, you want to deploy a demo version of your application without
321
# HD content. You could first change the title to add "(demo)" in the name
322
# and extend the excluded directories to remove the HD content.
323
#
324
#[app@demo]
325
#title = My Application (demo)
326
#
327
#[app:source.exclude_patterns@demo]
328
#images/hd/*
329
#
330
# Then, invoke the command line with the "demo" profile:
331
#
332
#buildozer --profile demo android debug
333
this is main.py:
JavaScript
1
63
63
1
import kivy
2
import platform
3
from kivy.app import App
4
from kivy.uix.label import Label
5
from kivy.uix.button import Button
6
from jnius import autoclass
7
from multiprocessing.dummy import Process
8
from kivy.uix.widget import Widget
9
import jnius
10
from kivy.clock import Clock
11
from kivy.uix.image import Image
12
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
13
14
15
16
class fscreen(Widget):
17
def __init__(self, **kwargs):
18
super().__init__(**kwargs)
19
20
21
class theapp(App):
22
def build(self):
23
self.cnt = 0
24
self.screenm = ScreenManager() #(transition=FadeTransition())
25
self.fscreen = fscreen()
26
screen = Screen(name = "first screen")
27
screen.add_widget(self.fscreen)
28
self.screenm.add_widget(screen)
29
return self.screenm
30
31
def change(self, *args):
32
self.cnt += 1
33
self.fscreen.ids.lb.text = str(self.cnt) + ' hello '
34
print(str(self.cnt) + ' hello ')
35
def label_update(self):
36
Clock.schedule_interval(self.change, 1)
37
38
def on_start(self):
39
from kivy import platform
40
41
if platform == "android":
42
43
self.start_service()
44
print('service started')
45
Process(target=self.label_update).start()
46
47
#@staticmethod
48
def start_service(self):
49
from android import mActivity
50
context = mActivity.getApplicationContext()
51
SERVICE_NAME = str(context.getPackageName()) + '.Service' + 'Worker'
52
service = autoclass(SERVICE_NAME)
53
print(SERVICE_NAME)
54
service.start(mActivity,'')
55
return service
56
print('returned service')
57
58
if __name__ == "__main__":
59
theapp = theapp()
60
theapp.run()
61
62
63
and this service.py:
JavaScript
1
15
15
1
import kivy
2
from kivy.app import App
3
from kivy.uix.screenmanager import ScreenManager, Screen
4
from kivy.uix.widget import Widget
5
from jnius import autoclass
6
import time
7
8
9
PythonService = autoclass('org.kivy.android.PythonService')
10
PythonService.mService.setAutoRestartService(True)
11
12
while True:
13
print('this is my service and its running')
14
time.sleep(1)
15
and this is the cat after adb logcat -s Worker
:
JavaScript
1
3
1
04-16 03:38:08.882 26990 27006 I Worker : this is my service and its running
2
04-16 03:38:09.884 26990 27006 I Worker : this is my service and its running
3