B4A Library MoPub Ad Server Library (Updated to v4.6.1 , 29 May 2016) - 20+ ad networks (AdMob , etc.)

mopub_logo.png

Library (Updated to v4.6.1 , 29 May 2016)
MoPub Official Website
Google Play Policies
MoPub is the world largest mobile ad server (mediation platform) and RTB exchange (MoPub marketplace). Now it belongs to Twitter. It is the main competitor to AdMob , but MoPub primary focus is mediation of ads. The following ad networks work just right out of the box:
MoPubLibVer.png

support.PNG
All networks are tested and use official java code of these networks.
AdColony can use only interstitial or rewarded video, if you will use both in your project - it will not work.
Tapjoy - please test, integration is rather complicated, so for now I didn't test it myself, but normally it should work.
Native ads are not supported for now.
Note: I advise you to use logcat logs in B4A (without filter checked) or this standalone utility to see all error codes and a lot of additional info about loading your ads.

Please vote for ad network you want to see in MoPub Library


ChangeLog:
v4.6.1 29.05.2016
v4.2 30.11.2015

Updated:
MoPub SDK v4.2 (Nov 30,2015)
All ad networks SDK's and code
Syntax of using library is changed a little
Added:
Rewarded video ads
Amazon ads
Tapjoy
Unity ads

v2.3 22.07.2014
Updated:
MoPub SDK v2.3 (Jul 17, 2014)
All ad networks SDKs
Added:
mNectar
MobileCore
Facebook
AdColony
Vungle
StartApp
Leadbolt

v2.1 02.12.2013
Added:
AppLovin (banners and interstitials)
Greystripe (banners and interstitials)
Chartboost (interstitials)

v2.0 28.11.2013
Added :
Banners and interstitials listeners
Interstitials' preload - now all works really fast
Integrated AppBrain and TapForTap
(both banners and interstitials)
Updated:
MoPub SDK v1.17 (Nov 20, 2013)
Appbrain SDK v9.2
TapForTap SDK v3.0.7
Fixed:
Interstitial's close button
Almost totally rewrited library

v1.1 16.06.2013
Added:
Interstitial ads

Roadmap:
Add support for Madvertise , RevMob , AppNext , Inneractive , TapContext , Amazon Ads , Flurry , MobPartner , MDotm
Note: possibly to make wrapper for MobFox as alternative to MoPub , because as from May 14, 2014 their SDK supports custom events to integrate other networks SDK , also maybe wrapper for mAdserve as self-hosting solution for mediating ads.


Tags: MoPub , MobFox , Mojiva , Lifestreet media , Hunt mobile ads , Tapit , AdMob , Millennial Media , Inmobi , Chartboost , Greystripe , AppBrain , TapForTap , MobileCore , AppLovin , Leadbolt , Facebook , AdColony , Vungle , StartApp , mNectar , Ad Network Library

Links:
MoPub B4A v4.6.1 update (Updated 29 May 2016)
MoPub B4A Library v4.2 Additional SDK's (Updated 30 November 2015)
I have included demo project with all listener methodes. You can compile that project with default id's to test ads.
Also I have written detailed but simple as possible guide to integrate all of the networks and general help how to use MoPub.
Soon I will update guide and published it, for now please see demo project.

Good luck !
Regards
John


 

Attachments

  • MoPub B4A Library v4.2.zip
    451.5 KB · Views: 558
Last edited:

base64

Member
Licensed User
Longtime User
Hello,
I've spent hours trying to make Vungle work.

I have a Custom Native Full Screen Ad on MoPub that supposedly links to my Vungle, and the way I set it up was:
  • Leaving Custom Event empty (as I did not see anything on the PDF guide on this)
  • Put "com.mopub.mobileads.VungleInterstitial" on Custom Event Class box
  • And, put "com.myapppackagename" on Custom Event Class Data box (I have also tried using the Reporting API ID instead of the App ID)
Everything in MoPub.xml and my manifest file have been set up according to what's in the guide PDF, including adding a write to external storage permission to the manifest.

I have the following in Activity_Create:
B4X:
ads.InitializeMopub_Banner("banner","")
ads.InitializeMopub_Interstitial("interstitial","xxxx")  ' where xxxx is my interstitial ID from MoPub
ads.PreloadMopub_Interstitial

and this:
B4X:
Sub interstitial_mopub_interstitial_loaded
    LogColor("Interstitial Loaded",Colors.Blue)
End Sub
Never gets called.

No error messages or anything in logs.

What am I missing or doing wrong here?
 

Johnmcenroy

Active Member
Licensed User
Longtime User
Hello,
I've spent hours trying to make Vungle work.

I have a Custom Native Full Screen Ad on MoPub that supposedly links to my Vungle, and the way I set it up was:
  • Leaving Custom Event empty (as I did not see anything on the PDF guide on this)
  • Put "com.mopub.mobileads.VungleInterstitial" on Custom Event Class box
  • And, put "com.myapppackagename" on Custom Event Class Data box (I have also tried using the Reporting API ID instead of the App ID)
Everything in MoPub.xml and my manifest file have been set up according to what's in the guide PDF, including adding a write to external storage permission to the manifest.

I have the following in Activity_Create:
B4X:
ads.InitializeMopub_Banner("banner","")
ads.InitializeMopub_Interstitial("interstitial","xxxx")  ' where xxxx is my interstitial ID from MoPub
ads.PreloadMopub_Interstitial

and this:
B4X:
Sub interstitial_mopub_interstitial_loaded
    LogColor("Interstitial Loaded",Colors.Blue)
End Sub
Never gets called.

No error messages or anything in logs.

What am I missing or doing wrong here?

Hi Base64
Please use guide to setup Vungle (Page 13)
All networks are tested manually by me.

Regards
John
 

base64

Member
Licensed User
Longtime User
Hi Base64
Please use guide to setup Vungle (Page 13)
All networks are tested manually by me.

Regards
John
Hello,
Thank you for the quick response!
I followed through that part of the guide when setting up my MoPub with Vungle, but it still doesn't work.
The sub interstitial_mopub_interstitial_loaded never gets called (and yes, I called PreloadMopub_Interstitial).

What else I could be missing or doing wrong?
 

Johnmcenroy

Active Member
Licensed User
Longtime User
Hello,
Thank you for the quick response!
I followed through that part of the guide when setting up my MoPub with Vungle, but it still doesn't work.
The sub interstitial_mopub_interstitial_loaded never gets called (and yes, I called PreloadMopub_Interstitial).

What else I could be missing or doing wrong?

Disable filter check in LogCat logs. Also make shure that Vungle is first network for your ad and you can disable Marketplace for testing purposes. In LogCat without filter checked you will see all info about loading ads.

Regards
John
 

base64

Member
Licensed User
Longtime User
Disable filter check in LogCat logs. Also make shure that Vungle is first network for your ad and you can disable Marketplace for testing purposes. In LogCat without filter checked you will see all info about loading ads.

Regards
John
Will try those! Thank you!
 

base64

Member
Licensed User
Longtime User
So, it appears that I get this in the log:

The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 5077000 but found 5089000. 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" />

although I already have that declaration in my manifest file (inside AddApplicationText(...)).

Which causes an IllegalStateException (the following is the next line in the log):
java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 5077000 but found 5089000. 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" />

How do I fix this?

I also get:
Unable to obtain AdvertisingIdClient.getAdvertisingIdInfo()
Is this a problem as well or it doesn't matter?


And here's the contents of my manifest file:
B4X:
'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: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="14"/>
)

AddApplicationText(
<!-- Vungle -->
<activity android:name="com.vungle.publisher.FullScreenAdActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
<service android:name="com.vungle.publisher.VungleService"
android:exported="false" />
<activity android:name="com.vungle.sdk.VungleAdvert"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
<service android:name="com.vungle.sdk.VungleIntentService"
android:exported="false"/>


<!-- MoPub -->
<activity android:name="com.mopub.mobileads.MoPubActivity"
android:configChanges="keyboardHidden|orientation"/>
<activity android:name="com.mopub.mobileads.MraidActivity"
android:configChanges="keyboardHidden|orientation"/>
<activity android:name="com.mopub.common.MoPubBrowser"
android:configChanges="keyboardHidden|orientation"/>
<activity android:name="com.mopub.mobileads.MraidVideoPlayerActivity"
android:configChanges="keyboardHidden|orientation"/>

<!-- Google Play Services -->
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />)


SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
 

Johnmcenroy

Active Member
Licensed User
Longtime User
So, it appears that I get this in the log:



although I already have that declaration in my manifest file (inside AddApplicationText(...)).

Which causes an IllegalStateException (the following is the next line in the log):


How do I fix this?

I also get:

Is this a problem as well or it doesn't matter?


And here's the contents of my manifest file:
B4X:
'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: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="14"/>
)

AddApplicationText(
<!-- Vungle -->
<activity android:name="com.vungle.publisher.FullScreenAdActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
<service android:name="com.vungle.publisher.VungleService"
android:exported="false" />
<activity android:name="com.vungle.sdk.VungleAdvert"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
<service android:name="com.vungle.sdk.VungleIntentService"
android:exported="false"/>


<!-- MoPub -->
<activity android:name="com.mopub.mobileads.MoPubActivity"
android:configChanges="keyboardHidden|orientation"/>
<activity android:name="com.mopub.mobileads.MraidActivity"
android:configChanges="keyboardHidden|orientation"/>
<activity android:name="com.mopub.common.MoPubBrowser"
android:configChanges="keyboardHidden|orientation"/>
<activity android:name="com.mopub.mobileads.MraidVideoPlayerActivity"
android:configChanges="keyboardHidden|orientation"/>

<!-- Google Play Services -->
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />)


SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")

It seems that Google Play Services are not properly integrated into application so Vungle can't obtain advertising ID. In MoPub Library I had 18 version of Goole Play Services (resource and jar). In your case it seems that you have updated your Google Play Services to 19 version but my Google Play Services jar is 18 version so it is not the same. Copy jar from here: YOUR_PATH_TO_ANDROID_SDK\extras\google\google_play_services\libproject\google-play-services_lib\libs to your B4A additional libraries folder . It must work.

Regards
John
 
Last edited:

base64

Member
Licensed User
Longtime User
It seems that Google Play Services are not properly integrated into application so Vungle can't obtain advertising ID. In MoPub Library I had 18 version of Goole Play Services (resource and jar). In your case it seems that you have updated your Google Play Services to 19 version but my Google Play Services jar is 18 version so it is not the same. Copy jar from here: YOUR_PATH_TO_ANDROID_SDK\extras\google\google_play_services\libproject\google-play-services_lib\libs to your B4A additional libraries folder . It must work.

Regards
John

It works! Thank you very much!
 

gmh

New Member
Licensed User
Longtime User
Hi, I’m having a lot of trouble getting Interstitial Ads working.

I get -

java.lang.NoClassDefFoundError: android.support.v4.content.LocalBroadcastManager
at com.mopub.mobileads.EventForwardingBroadcastReceiver.register(EventForwardingBroadcastReceiver.java:113)

I suspect it is due to the Google Play Services which is currently at version 22. I use Google Maps APi v2.0, which uses Google play, so I am confident that this is entered correctly. I have also copied it into my B4A additional libraries folder (as per previous entry).

Any help appreciated,
Thanks

Geoff
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
Hi, I’m having a lot of trouble getting Interstitial Ads working.

I get -

java.lang.NoClassDefFoundError: android.support.v4.content.LocalBroadcastManager
at com.mopub.mobileads.EventForwardingBroadcastReceiver.register(EventForwardingBroadcastReceiver.java:113)

I suspect it is due to the Google Play Services which is currently at version 22. I use Google Maps APi v2.0, which uses Google play, so I am confident that this is entered correctly. I have also copied it into my B4A additional libraries folder (as per previous entry).

Any help appreciated,
Thanks

Geoff

Yeah - I think you need to use an earlier version of Google Play Services. Maybe try 18? I think I'm using 14, but that's because I'm using an old Play Services wrapper.
 

ykucuk

Well-Known Member
Licensed User
Longtime User
Hello,

i have a problem when i try to run my app.

i replaced my google-play-services_lib with b4a folder . no luck.

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/google/ads/AdRequest$Gender;
at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
at com.android.dx.command.dexer.Main.processClass(Main.java:685)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
at com.android.dx.command.dexer.Main.access$600(Main.java:78)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:596)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
1 error; aborting
Optimized dexer failed. Switching to Standard dexer.
 

Ricardo Bunschoten

Active Member
Licensed User
Longtime User
I use now admob in my apps and this lbirary look indeed better to support video adds from addmob.

But is there a tutorial how to use this library in combination with Admob/admob video tutorials ?
 

MaxApps

Active Member
Licensed User
Longtime User
Can I use this without Google Play Service? (I have been banned from Google)
 

Johnmcenroy

Active Member
Licensed User
Longtime User
Can I use this without Google Play Service? (I have been banned from Google)
Hi MaxApps
Google Play Services are used to pass Google Advertising ID that is using instead old Android ID.
Since August 1, 2014 all apps must use new Google Advertising ID, so I think just any ad network is using it (MoPub also, but it must depend on network you are using through MoPub), there are some networks that don't use it.
Also for more info look here.
Anyway I don't see a problem using Google Play Services even though you have been banned by Google because it is not associated with your account, it is anonymous user's identifier, who uses your application.

Regards
John
 

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

I get Banner Failed and also Interstitial Failed when tapping the Show Banner and Preload Interstitial buttons from the sample test app.

I also registered with mopub in the US and tried the same thing with the ad unit id in admob_test and admob_banner and still got the same error message.

Here is the coding I used:

B4X:
#Region  Project Attributes
    #ApplicationLabel: MoPub TEST
    #VersionCode: 1
    #VersionName: 1.0
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #AdditionalRes: C:\Program Files (x86)\Android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms
#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
    Dim ads As MopubAds
  
    Dim btnShowBanner As Button
    Dim btnDestroyBanner As Button
  
    Dim btnPreload As Button
    Dim btnShow As Button
  
    Dim LogLabel As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout ("main")
    ads.AdMob_Test("")
    ads.InitializeMopub_Banner("banner","")
    ads.InitializeMopub_Interstitial ("interstitial","")
End Sub

Sub Activity_Resume
  
End Sub

Sub Activity_Pause (UserClosed As Boolean)
  
End Sub

'Banners Buttons
Sub btnShowBanner_Click
    LogLabel.Text = ""
    ads.RemoveView
    Activity.AddView (ads,0,0,320dip,50dip)
    ads.LoadMopub_Banner
End Sub

Sub btnDestroyBanner_Click
    ads.RemoveView
End Sub

'Interstitials Buttons
Sub btnPreload_Click
    LogLabel.Text = ""
    ads.PreloadMopub_Interstitial
End Sub

Sub btnShow_Click
    ads.ShowMopub_Interstitial
End Sub

'Banners Listener methodes
Sub banner_mopub_banner_clicked
    LogColor("Banner Clicked",Colors.Green)
End Sub

Sub banner_mopub_banner_collapsed
    LogColor("Banner Collapsed",Colors.Green)
End Sub

Sub banner_mopub_banner_expanded
    LogColor("Banner Expanded",Colors.Green)
End Sub

Sub banner_mopub_banner_failed
    LogColor("Banner Failed",Colors.Green)
    LogLabel.Text = "Banner Failed"
End Sub

Sub banner_mopub_banner_loaded
    LogColor("Banner Loaded",Colors.Green)
    LogLabel.Text = "Banner Loaded"
End Sub

'Interstitials Listener methodes
Sub interstitial_mopub_interstitial_clicked
    LogColor("Interstitial Clicked",Colors.Blue)
End Sub

Sub interstitial_mopub_interstitial_dismissed
    LogColor("Interstitial Dismissed",Colors.Blue)
End Sub

Sub interstitial_mopub_interstitial_failed
    LogColor("Interstitial Failed",Colors.Blue)
    LogLabel.Text = "Interstitial Failed"
End Sub

Sub interstitial_mopub_interstitial_loaded
    LogColor("Interstitial Loaded",Colors.Blue)
    LogLabel.Text = "Interstitial Loaded"
End Sub

Sub interstitial_mopub_interstitial_shown
    LogColor("Interstitial Shown",Colors.Blue)
End Sub

What am I missing?

Thanks.
 

tufanv

Expert
Licensed User
Longtime User
I cant get chartboost interstitial via mpub. I get interstitial filed under logs. I added additionaljar and edited the manifest but still cant get it.
 
Top