B4A Library FirebaseAdMob v1.6

Status
Not open for further replies.

Erel

Administrator
Staff member
Licensed User
Google has added a few new requirements to AdMob implementation. You must make these changes if you are using the latest versions of Android SDK libraries (firebase-ads 18.1.1+).

Instructions:
1. Download the attached library and copy it to the internal libraries folder. This step is not needed if using B4A v9.5+.
2. Find your AdMob app id and add it to the manifest editor:
B4X:
'This is a sample AdMob app id. You need to change it to your id.
AddReplacement($ADMOB_APP_ID$, ca-app-pub-3940256099942544~3347511713)
How to find the id: https://support.google.com/admob/answer/7356431?hl=en

3. Initialize MobileAds in Service_Create of the starter service:
B4X:
Dim MobileAds As MobileAds
MobileAds.Initialize
4. Open Tools - B4A Sdk Manager and update all the recommended items.

If the app immediately crashes then it is likely that the app id is wrong. Start with the sample app id and then change it to your app id.
 

Attachments

Last edited:

rraswisak

Active Member
Licensed User
I follow instruction above, but app immediately crash, also in B4A Sdk Manager all recomended component was installed. The log says:

Start proc 2781:com.rra.sbac.id/u0a74 for activity com.rra.sbac.id/.main
ClassLoader referenced unknown path: /data/app/com.rra.sbac.id-1/lib/x86
gralloc_alloc: Creating ashmem region of size 4096000
Shutting down VM
FATAL EXCEPTION: main
Process: com.rra.sbac.id, PID: 2781
java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.ads.MobileAdsInitProvider" on path: DexPathList[[zip file "/data/app/com.rra.sbac.id-1/base.apk"],nativeLibraryDirectories=[/data/app/com.rra.sbac.id-1/lib/x86, /system/lib, /vendor/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:5814)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5403)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5342)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.ads.MobileAdsInitProvider" on path: DexPathList[[zip file "/data/app/com.rra.sbac.id-1/base.apk"],nativeLibraryDirectories=[/data/app/com.rra.sbac.id-1/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.ActivityThread.installProvider(ActivityThread.java:5799)
... 10 more
Force finishing activity com.rra.sbac.id/.main
Initialized EGL, version 1.4
Swap behavior 1
Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
Swap behavior 0
eglCreateContext: 0x8f6eaa20: maj 2 min 0 rcv 2
eglMakeCurrent: 0x8f6eaa20: ver 2 0 (tinfo 0x93331160)
eglMakeCurrent: 0x8f6eaa20: ver 2 0 (tinfo 0x93331160)
Activity pause timeout for ActivityRecord{bcfce40 u0 com.rra.sbac.id/.main t171 f}
Failed to capture screenshot of Token{dd28179 ActivityRecord{bcfce40 u0 com.rra.sbac.id/.main t171 f}} appWin=Window{fcb5796 u0 Starting com.rra.sbac.id} drawState=3
Destroying surface Surface(name=Starting com.rra.sbac.id) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.removeLocked:1449 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2478 com.android.server.wm.WindowManagerService.removeWindowLocked:2436 com.android.server.wm.WindowManagerService.removeWindowLocked:2305 com.android.server.wm.WindowManagerService.removeWindow:2300 com.android.server.wm.Session.remove:193
Activity destroy timeout for ActivityRecord{bcfce40 u0 com.rra.sbac.id/.main t171 f}


Manifest:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'CreateResourceFromFile(Macro, Themes.DarkTheme)
SetApplicationAttribute(android:largeHeap, "true")
SetApplicationAttribute(android:theme, "@style/LightTheme")
CreateResource(values, colors.xml,
<resources>
<color name="bground">#ff000000</color>
</resources>
)
CreateResource(values-v20, theme.xml,
<resources>
<style
name="LightTheme" parent="@android:style/Theme.Material.Light.NoActionBar.Fullscreen">
</style>
</resources>
)
CreateResource(values-v14, theme.xml,
<resources>
<style
name="LightTheme" parent="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen">
<item name="android:windowBackground">@color/bground</item>
</style>
</resources>
)
'End of default text.
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseAdMob.FirebaseAds)
CreateResourceFromFile(Macro, FirebaseAuth.FirebaseAuth)

AddReplacement($ADMOB_APP_ID$, ca-app-pub-9753190058764240~4468921026)

What is the problem and what should i do ?
 

Erel

Administrator
Staff member
Licensed User
Based on the error message you are not using the latest version of firebase-ads. Check it in B4A Sdk Manager. It should be 18.1.1+. Also make sure that the IDE is configured to use the correct SDK - Tools - Configure Paths - android.jar.
 

rraswisak

Active Member
Licensed User
Thank you Erel, i can confirm that the problem was solved right now.

Previous error is because i still use SDK 27 for android.jar in configure path. Now using SDK 28 the app run as usual
 

dragonguy

Active Member
Licensed User
When we using Google-provided test ad units for test our app, so we need add the real one
AdMob app id or testing AdMob app id?

Google-provided test ad app id
B4X:
ca-app-pub-3940256099942544~6300978111
 

Erel

Administrator
Staff member
Licensed User
I don't think that it matters however you can always use the test app id: ca-app-pub-3940256099942544~3347511713
 

Scantech

Well-Known Member
Licensed User
First Question: AddReplacement($ADMOB_APP_ID$, ca-app-pub-3940256099942544~3347511713)

$ADMOB_APP_ID$ = App ID
ca-app-pub-3940256099942544~3347511713 = ?? Where do i find this??

Second Question: I use
B4X:
Private mwAdInterstitial As InterstitialAd
Do i need
B4X:
Dim MobileAds As MobileAds
MobileAds.Initialize
 

tufanv

Expert
Licensed User
Is this update has to be made or can I continue to use old library with older firebase ?
 

sorex

Expert
Licensed User
what is this additional piece of code doing and why does it need the placement id when you use it later again to initialize the placement?

is this related to that ads.txt or whatever it was?
 

Erel

Administrator
Staff member
Licensed User
Technically you can continue to use the old library with the old versions of the firebase items.

Google do recommend to add the app id (and use the latest version of Firebase) so it is probably a good idea to update it soon.
 

Erel

Administrator
Staff member
Licensed User
what is this additional piece of code doing and why does it need the placement id when you use it later again to initialize the placement?
It is not the placement id. It is the app id.
It is not related to ads.txt.

In the latest version of AdMob it will throw an error if the app id is missing from the manifest file.
 

sorex

Expert
Licensed User
ok, thanks.

a lot of updating to do these days if you want to stay conform their 'wishes'.
 

tufanv

Expert
Licensed User
I have a confusion here. I use more than one interstitial ad ids, some has higher ecpm floor some does not have. With the new version I don't see any place to use these ids. So do I leave the old code on the main module as it is, and just add these piece of code to starter ?
It is not the placement id. It is the app id.
It is not related to ads.txt.

In the latest version of AdMob it will throw an error if the app id is missing from the manifest file.
 

tufanv

Expert
Licensed User
I did as I mentioned above, My app instantly crashes on launch. My app id is correct. I also tried with the sample app id, I cant even get a log. I will open a new thread for this problem
 
Last edited:
Status
Not open for further replies.
Top