Search code examples
pythonandroidkivybuildozerreferenceerror

I'm receiveing ReferenceError when i build Kivy app on my android trough Buildozer


My app crashes every single time i search for a location on my map trough an android phone after i get it buit trough Buildozer, despite it working perfectly fine on my PC.

I receive ReferenceError:weakly-referenced object no longer exists.

Main File

import sqlite3
from kivymd.app import MDApp
from farmersmapview import FarmersMapView
from searchpopupmenu import SearchPopupMenu



class MainApp(MDApp):


connection = None
cursor = None
search_menu = None
def on_start(self):

    self.theme_cls.primary_palette = "LightGreen"
    self.theme_cls.accent_palette = "Teal"
    self.theme_cls.theme_style="Light"
    #Inititalize GPS


    #Connect to database (DB file)
    self.connection=sqlite3.connect("markets.db")
    self.cursor = self.connection.cursor()

    #instantiate SearchPopupMenu
    self.search_menu = SearchPopupMenu()
  MainApp().run()

FarmersMapView file

class FarmersMapView(MapView):
   market_names=[]
   getting_markets_timer = None

def start_getting_markets_in_fov(self):
    #After one seconds get the markets in the fov
    try:
        self.getting_markets_timer.cancel()
    except:
        pass

    self.getting_markets_timer = Clock.schedule_once(self.get_markets_in_fov, 1)

def get_markets_in_fov(self, *args):

    #get reference to main app and database cursor
    min_lat, min_lon, max_lat, max_lon = self.get_bbox()
    app = App.get_running_app()#returns main app when running
    sql_statement = "SELECT * FROM markets WHERE x > %s AND x < %s AND y > %s AND y < %s "%(min_lon, max_lon, min_lat, max_lat)#sql_stmnt is just a variable
    app.cursor.execute(sql_statement)
    markets = app.cursor.fetchall()#Returns a list from app.cursor
    print(markets)

    for market in markets:
        name = market[1]
        if name in self.market_names:
            continue
        else:
            self.add_market(market)

def add_market(self, market):

    # create MarketMarker
    lat, lon = market[21], market[20]#each market is a list of info where lat located at index 21 and lon at index 20
    marker = MarketMarker(lat=lat, lon=lon, source=image)
    marker.size=(35,35)

    marker.market_data=market#wtf is going on here

    #add MarketMarker to the map
    self.add_widget(marker)


    #Keep track of the MarketMarker's name (to avoid duplicates)
    name = market[1]
    self.market_names.append(name)

I've spent around 3 days trying to solve this problem. Tried deleting all kivy.clock references from my code, tried to search and replace my weakly-referenced objects into strong-referenced objects, tried to specify python and kivy versions in buildozer.spec, tried to re-install ubuntu, tried going into weakmethod.py and replacing dead_method() code into this

try:
    return self.proxy is not None and not bool(dir(self.proxy))
except ReferenceError:
    return True

There's a strong suspicion that problem is in the get_markers_in_fov, so i tried to rewrite it in a strong-referenced object manner but it didn't work out. I'm very new to programming so i might've miss something there.

it happens this way: https://youtu.be/XKLO6euSEBk


Solution

  • I installed xubuntu instead of ububntu and usded fresher buildozer tutorual to set everything up and problem has been solved