Kivy + Admobs integration using Pyjunius results in an error 0 : Adview does not have fbind

15 Views Asked by At

Below is the error that I captured from logcat trace.

02-15 10:48:01.846 23927 23971 I python  :  Traceback (most recent call last):
02-15 10:48:01.847 23927 23971 I python  :    File "/home/venture/CODE/kivads/02/.buildozer/android/app/main.py", line 44, in <module>
02-15 10:48:01.848 23927 23971 I python  :    File "/home/venture/CODE/kivads/02/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/msqt_ads/arm64-v8a/kivy/app.py", line 955, in run
02-15 10:48:01.848 23927 23971 I python  :    File "/home/venture/CODE/kivads/02/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/msqt_ads/arm64-v8a/kivy/app.py", line 925, in _run_prepare
02-15 10:48:01.849 23927 23971 I python  :    File "/home/venture/CODE/kivads/02/.buildozer/android/app/main.py", line 20, in build
02-15 10:48:01.850 23927 23971 I python  :    File "/home/venture/CODE/kivads/02/.buildozer/android/app/main.py", line 37, in add_admob_banner
02-15 10:48:01.850 23927 23971 I python  :    File "/home/venture/CODE/kivads/02/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/msqt_ads/arm64-v8a/kivy/uix/boxlayout.py", line 326, in add_widget
02-15 10:48:01.852 23927 23971 I python  :  AttributeError: 'com.google.android.gms.ads.AdView' object has no attribute 'fbind'
02-15 10:48:01.852 23927 23971 I python  : Python for android ended.

I am using buildozer for building the android app - and there are no errors in build process.

Below requirements are added to the spec file :

requirements = Cython==0.29.33,Kivy==2.2.1,plyer==2.1.0,pyjnius==1.6.1,python-for-android==2023.9.16 android.gradle_dependencies = com.google.android.gms:play-services-ads:22.0.0,com.google.firebase:firebase-ads:22.0.0 android.enable_androidx = True

The code is rather simple

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label

from jnius import autoclass

AD_UNIT_ID = "your_ad_unit_id"
APP_ID = "your_app_id"
class AdMobApp(App):
    def build(self):
        # Create the layout
        layout = BoxLayout(orientation='vertical')
        label = Label(text="Hello Kivy with AdMob!")
        layout.add_widget(label)
        # Add AdMob banner ad
        self.add_admob_banner(layout)
        return layout

    def add_admob_banner(self, layout):
        # Load necessary classes from the Android API
        PythonActivity = autoclass('org.kivy.android.PythonActivity')
        AdView = autoclass('com.google.android.gms.ads.AdView')
        AdSize = autoclass('com.google.android.gms.ads.AdSize')
        AdRequest = autoclass('com.google.android.gms.ads.AdRequest')

        # Create the AdMob banner
        ad_view = AdView(PythonActivity.mActivity)
        ad_view.setAdUnitId(AD_UNIT_ID)
        ad_view.setAdSize(AdSize.SMART_BANNER)

        # Add the AdMob banner to the layout
        layout.add_widget(ad_view)

        # Load the AdMob ad
        ad_request = AdRequest.Builder().build()
        ad_view.loadAd(ad_request)

if __name__ == '__main__':
    AdMobApp().run()
0

There are 0 best solutions below