Her my main.py
# -*- coding: utf-8 -*-
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager,Screen,FadeTransition
from kivy.lang import Builder
from kivy.properties import ObjectProperty, StringProperty
from kivy.core.text import LabelBase
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from kivy.storage.jsonstore import JsonStore
class MainWindow(Screen):
pass
class SecondWindow(Screen):
stored_data = ObjectProperty(None)
def __init__(self,*args,**kwargs):
super(Screen,self).__init__(*args,**kwargs),
self.stored_data = JsonStore('data.json')
def gonder(self):
name = self.ids.name.text
scope = ["https://spreadsheets.google.com/feeds",
'https://www.googleapis.com/auth/spreadsheets',
"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("creds.json", scope)
client = gspread.authorize(creds)
sheet = client.open("verigonder").sheet1
sheet.append_row([name])
class ThirdWindow(Screen):
pass
class WindowManager(ScreenManager):
pass
class mainApp(App):
def build(self):
return Builder.load_file("my.kv")
if __name__ == "__main__":
mainApp().run()
and buildozer.spec requirements is here
requirements = python3,kivy,gspread,oauth2client,google-auth-oauthlib,httplib2,pyasn1,pyasn1-modules,rsa,request,google
and log of debug
06-02 15:25:27.121 25609 25949 I python : Traceback (most recent call last):
06-02 15:25:27.121 25609 25949 I python : File
"/home/ademberkaksoy/sheet/.buildozer/android/app/main.py", line 8, in <module>
06-02 15:25:27.121 25609 25949 I python : File
"/home/ademberkaksoy/sheet/.buildozer/android/platform/build-armeabi-v7a/build/python-
installs/myapp/gspread/__init__.py", line 16, in <module>
06-02 15:25:27.121 25609 25949 I python : File
"/home/ademberkaksoy/sheet/.buildozer/android/platform/build-armeabi-v7a/build/python-
installs/myapp/gspread/auth.py", line 12, in <module>
06-02 15:25:27.121 25609 25949 I python : ModuleNotFoundError: No module named 'google'
06-02 15:25:27.121 25609 25949 I python : Python for android ended.
it is still giving same error. What I need to do for fix this situation? Its working on laptop, but it doesnt work on android because of this error. I thinks its all about the gspread but where is the problem why is still giving this error ?
TL;DR: Add google-auth
to your existing requirements
of your buildozer.spec
Long story:
Yes buildozer/p4a can't do automatic package dependency resolution by default yet.
So the way we want to debug this is by finding ourselves which package is missing. From the stacktrace check this part:
06-02 15:25:27.121 25609 25949 I python : File
"/home/ademberkaksoy/sheet/.buildozer/android/platform/build-armeabi-v7a/build/python-
installs/myapp/gspread/auth.py", line 12, in <module>
06-02 15:25:27.121 25609 25949 I python : ModuleNotFoundError: No module named 'google'
And then see for the gspread
package and auth
module what exactly it's trying to import. Check that from the source code: https://github.com/burnash/gspread/blob/v3.6.0/gspread/auth.py#L12
from google.oauth2.credentials import Credentials
So now we need to see on which package the Credentials
class is being defined.
There're multiple ways to find that, but since we know it must be a dependency we check the setup.py
of that same package.
https://github.com/burnash/gspread/blob/v3.6.0/setup.py#L46-L50
install_requires=[
'requests>=2.2.1',
'google-auth>=1.12.0',
'google-auth-oauthlib>=0.4.1'
],
Here we see 3 dependencies to look from. We could then search further to see if that class is defined in one of them. But actually there're dependencies we would need no matter what. So we can simply add them to then buildozer.spec
and then buildozer android clean
and buildozer android debug
.
That should be it.
But if we're curious still here's where it's really defined https://github.com/googleapis/google-auth-library-python/blob/v1.16.0/google/oauth2/credentials.py#L50 then checking that project README we see it indeed comes from the google-auth
package.