Search code examples
pythonandroidandroid-studiokivybuildozer

How to make kivy urlrequests work with my android apk made in buildozer


Im making a moblie app which will use kivy UrlRequests, on ubuntu and macos the app works but when i make a apk with buildozer and run it on my android (OnePlus 5: android 9.0.8) via android studios the application works until the UrlRquest part where it crashes.

Ive made a test apk just to isolate and test the UrlRequest and it works on my pc/laptop and kivy launcher but not as a apk on android.

I also have the buildozer.spec and logcat file let me know if you need

Ive tried and changed the Buildozer.spec permisions and requirements to: android.permissions = INTERNET,ACCESS_NETWORK_STATE

requirements = kivy,android,openssl,pyopenssl,httplib2

I have also tried to change https to http but still no luck

from kivy.clock              import Clock
from kivy.lang               import Builder
from kivy.network.urlrequest import UrlRequest
from kivy.uix.boxlayout      import BoxLayout


Builder.load_string('''
<DemoLayout>:
  orientation: "vertical"
  padding:     50
  spacing:     50

  Button:
    size_hint: (0.3, 0.3)
    pos_hint:  {"center_x": 0.5}
    text:      "Make Request"
    on_press:  app.make_request()

  Label:
    id: result_label
''')


class DemoLayout(BoxLayout):
  pass


class Demo(App):
  def build(self):
    return DemoLayout()

  def on_request_success(self, request, result):
    self.root.ids.result_label.text = str(result["data"][0]["amount"])

  def make_request(self, *args):
    UrlRequest(
      url         = "https://api.coinbase.com/v2/prices/GBP/spot?",
      on_error    = None,
      on_failure  = None,
      on_progress = None,
      on_redirect = None,
      on_success  = self.on_request_success,
      timeout     = 5,
    )


Demo().run()

I expect the output to be a value fro btc when the "Make Request" button is pressed, but the actual output is nothing


Solution

  • I found a solution at http://www.jiajianhudong.com/question/3324796.html I updated my buildozer requirments to add certfi and added ca_file=certifi.where() parameter to my UrlRequest()