I installed JDK and Visual Studio. I can import other classes without any problem, but I keep getting errors while importing the PythonActivity class.
I am using javac 14.0.2 and C++
my codes:
import kivy
from kivy.app import App
from kivy.uix.label import Label
from jnius import autoclass
PythonActivity = autoclass('org.kivy.android.PythonActivity')
class MyApp(App):
def build(self):
return Label(text=str(type(PythonActivity)))
if __name__=="__main__":
MyApp().run()
and errors:
PythonActivity = autoclass('org.kivy.android.PythonActivity')
File "D:\DNDR\Yeni klasör\lib\site-packages\jnius\reflect.py", line 229, in autoclass
c = find_javaclass(clsname)
File "jnius\jnius_export_func.pxi", line 26, in jnius.find_javaclass
File "jnius\jnius_utils.pxi", line 91, in jnius.check_exception
jnius.JavaException: JVM exception occurred: org/kivy/android/PythonActivity java.lang.NoClassDefFoundError
The activity is created for android app, so in this case pyjnius will be used android app to access class. You have to just code, compile and run on Android. The activity is of android app. The buildozer or p4a create activity file. So try building using p4a or buildozer and then run on Android emulator or device and then check for log.
I have used this in my project. I have l build apk using buildozer. The app works fine.
https://github.com/infinyte7/Mandarin-News-Feed/blob/master/Mandarin%20News%20Feed/main.py#L46
https://github.com/infinyte7/Mandarin-News-Feed/blob/master/Mandarin%20News%20Feed/main.py#L670