Android Question Fail to load ad

catyinwong

Active Member
Licensed User
Longtime User
Trying to add advertisement into an app. There is an error when the app tries to load the add: java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="@Integer/google_play_services_version" />

The error occurs on the line "BannerAd.LoadAd". Anyone knows why?


B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim BannerAd As AdView
    Dim IAd As InterstitialAd
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim p As Panel = LoadAd("ca-app-pub-5725771019370401/3534296381")
    Activity.AddView(p,0,0,p.Width,p.Height)
End Sub

Sub LoadAd(AdID As String) As Panel
    Dim height As Int
    If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
        'phones
        If 100%x > 100%y Then height = 32dip Else height = 50dip
    Else
        'tablets
        height = 90dip
    End If
    
    BannerAd.Initialize("BannerAd", AdID)

    BannerAd.Width = 100%x
    BannerAd.Height = height
    
    Dim p As Panel: p.initialize("BannerAd")
    p.Width = BannerAd.Width
    p.Height = BannerAd.Height
    p.AddView(BannerAd,0,0,p.Width,p.Height)
    
    BannerAd.LoadAd
    
    Return p
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 

catyinwong

Active Member
Licensed User
Longtime User
Errrr - yes. Because you haven't implemented AdMob correctly. Take a look at the tutorial -> https://www.b4x.com/android/forum/t...b-ads-integrated-with-firebase-backend.67710/

- Colin.

I have already followed the steps, still new kind of error pop up every time...


1. Use B4A Sdk Manager tool to install all recommended items.
I did, and even uninstalled and reinstalled the B4A once to make sure all libraries and items are of the latest version.

2. Register with Firebase and create a new project: https://console.firebase.google.com/
Make sure that the package name matches your app's package name.

I did. The package names match.

3. Download google-services.json and put it in the projects folder (folder of the b4a file).
I did.

4. Add the manifest snippets to the manifest editor based on the services that you need.
Not sure what to add. Nothing written in the tutorial thread.

5. Follow the instructions of the specific libraries.
Simply copies the codes from the tutorial thread. But it doesn't work.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
4. Add the manifest snippets to the manifest editor based on the services that you need.
Not sure what to add. Nothing written in the tutorial thread.

The 4th paragraph in the Firebase AdMob tutorial says:

First you need to follow the Firebase integration tutorial: https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/
Make sure to include the Ads manifest snippet.

If you read that you'd know which manifest snippets to add.

EDIT: Actually, you obviously did go to the Firebase integration tutorial, but you didn't read the whole thing. Read past where it says:

Update - If you are using B4A v8+:

If you are using an older version than v8+, scroll down & click on the button that says "Spoiler: Older Versions:"

- Colin.
 
Last edited:
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
There's something not right in your manifest. Post the contents on here.

- Colin.
 
Upvote 0
Top