B4A Library FirebaseAdMob - Admob ads integrated with Firebase backend

Status
Not open for further replies.

andymc

Well-Known Member
Licensed User
Longtime User
I've just updated to use firebase ads but am now getting this error when starting my game:

** Activity (main) Resume **
main_activity_resume (java line: 916)
java.lang.RuntimeException: Object should first be initialized (AdView).
Did you forget to call Activity.LoadLayout?
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.admobwrapper.AdViewWrapper.Resume(AdViewWrapper.java:140)
at uk.co.coffeeinducedgames.invaders.main._activity_resume(main.java:916)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)


I initialise my adview object in the activity_create method as I always have but now this error is showing. I have also moved my target SDK up to 24 from 16 if that makes any difference.
 

DonManfred

Expert
Licensed User
Longtime User
>I've just updated to use firebase

Did you replaced the old adview view from your layout and replaced it with the adview from firebaseads? I mean; if there are any views in the designer (i dont use Ads so i can´t answer this). Just an idea...
 
Last edited:

Vincenzo Fabiano

Member
Licensed User
Longtime User
I have this error on compile....

B4X:
B4A Versione: 7.30
Analisi del Codice.    (0.09s)
Compilazione del codice.    (0.16s)
Compilazione del codice di layouts    (0.02s)
Organizzazione Librerie.    (0.00s)
Generazione file R.    Error
AndroidManifest.xml:33: error: Error: No resource found that matches the given name (at 'label' with value '@string/app_name').
AndroidManifest.xml:41: error: Error: No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version').
AndroidManifest.xml:99: error: Error: No resource found that matches the given name (at 'theme' with value '@style/Theme.IAPTheme').

Any solution? :/
 
Last edited:

Computersmith64

Well-Known Member
Licensed User
Longtime User
The manifest can't find those resources. Have you created a values file & placed it in your resources directory? If so, did you make it read only?

If you haven't created that file, I suggest you read the Firebase tutorials - firstly the one about integrating firebase generally, then the one about firebase ads.

- Colin.
 

Vincenzo Fabiano

Member
Licensed User
Longtime User
I fixed whit this and removed my res folder (obsolete):

#AdditionalJar: com.google.android.gmslay-services-analytics
#AdditionalJar: com.google.android.gmslay-services-ads
 

analizer3816

Member
Licensed User
Longtime User
please add admob native advanced
B4X:
https://developers.google.com/admob/android/native-advanced

because google send email to me that admob native express will not work on march 1,2018
and cannot create new native express after october 23,2017
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
Native Ads advanced is not publicly available. It is in a limited beta state.
That's true, but the documentation is available online. I have received an email from AdMob asking me to try out Native Advanced ads & links to the relevant documentation. I can try it on my iOS apps (because I wrote them in Swift) but I'm not sure about my Android ones developed with B4A, as I assume the FirebaseAdMob library doesn't support them.

Here's a link to the documentation - I don't know if you can get test ads if you're not a beta tester, but it might be useful...

https://developers.google.com/admob/android/native-advanced

- Colin.
 
Last edited:

hasexxl1988

Active Member
Licensed User
Longtime User
Hello,
I'm doing something wrong and I'm not on it.

The test IDs work perfectly.

Not my own.

I've created the Firebase account (Appname is the same as Admob or B4A.)
I've linked Firebase to Admob.
I have created 2 adblocks (1x banner, 1x interstitial)

But I'm not shown anything, neither banner nor interstitial.

google.services.json from Firebase is in the B4A Projectfolder.

i have Add all Texts to Mainfest from: https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/


 

Computersmith64

Well-Known Member
Licensed User
Longtime User
Can you post your code?
 

hasexxl1988

Active Member
Licensed User
Longtime User
Can you post your code?
B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private BannerAd As AdView
    Private 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")

    IAd.Initialize("iad", "MyInterstitialID")
    IAd.LoadAd
End Sub

Sub Activity_Click
End Sub

Sub IAD_AdClosed
    IAd.LoadAd 'prepare a new ad
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button2_Click
    BannerAd.Initialize2("BannerAd", "MyBannerID", BannerAd.SIZE_SMART_BANNER)
    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
    Activity.AddView(BannerAd, 0dip, 100%y - height, 100%x, height)
    BannerAd.LoadAd
End Sub

Sub Button1_Click
    If IAd.Ready Then IAd.Show
  
End Sub

I have 2 buttons added for testing each Ads. Works with the Test IDs.

EDIT:

Do I need to enter the Publisher-ID of Admob, or the Firebase App-ID / Web API-Key somewhere?
 
Last edited:

Computersmith64

Well-Known Member
Licensed User
Longtime User

Your ad id ("MyInterstitialID") should look something like "ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx". You should also implement the ReceivedAd & FailedToReceiveAd callbacks so that you can get more visibility into whether you are actually receiving the ads or if there's an error somewhere.

- Colin.
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
B4X:
Private Sub adMob_ReceiveAd
    Log("ad loaded")
End Sub

Private Sub adMob_FailedToReceiveAd(ErrorCode As String)
    Log("failed to load ad: " & ErrorCode)
End Sub
 

hasexxl1988

Active Member
Licensed User
Longtime User
i have MyInterstitialID removed for posting here.

Callback in the Log is Errorcode 0:
Failed: 0
 
Last edited:

Computersmith64

Well-Known Member
Licensed User
Longtime User
i have MyInterstitialID removed for posting here. The ID for Interstitial is: ca-app-pub-4940153087607272/5013832462

Callback in the Log is Errorcode 0:
Failed: 0
From Google:


Also, it could just be that there are no ads available...

- Colin.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…