A B4A (Basic4android) library that wraps the Adivery Android SDK: interstitial, rewarded, App Open, Offer Wall and banner ads, used from B4A code.
Repo layout:
b4a-plugin/src/com/adivery/b4a/ → the Java wrapper, compiled into Adivery.jar + Adivery.xml by B4A's LibraryCompiler
sample/ → a B4A sample project (ui_example.b4a) that shows every format
build.bat → runs LibraryCompiler (Windows only)
.claude/skills/ → Claude Code skills to sync with a new SDK version and to publish a release
The full guide, in Persian, is at docs.adivery.com/b4a. In short:
-
Download
adivery-b4a.zipfrom the latest release. ExtractAdivery.jar,Adivery.xmlandAdivery.aar(the Adivery SDK) into your B4A Additional Libraries folder, and tick Adivery in the Libraries tab. -
B4A doesn't resolve the SDK's own dependencies. Download these jars from Maven Central into the same folder (the docs link each one), and add them to your project:
#AdditionalJar: kotlin-stdlib-2.1.10 #AdditionalJar: okhttp-4.12.0 #AdditionalJar: okio-jvm-3.6.0 #AdditionalJar: sentry-8.7.0 #AdditionalJar: kotlinx-coroutines-core-jvm-1.10.1 #AdditionalJar: kotlinx-coroutines-android-1.10.1
The two
kotlinx-coroutinesjars are new in v4.10.0-alpha.1. Without them, ads fail to load. -
Declare the SDK's ad activity in the Manifest Editor:
AddApplicationText( <activity android:name="com.adivery.sdk.networks.adivery.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:exported="false" />)
-
Let the SDK read the advertising ID. B4A doesn't merge the SDK's own manifest, and on Android 13+ Google Play services returns an all-zero ID to apps that don't declare
AD_ID, so the server has nothing to target and can return no ads (the offer wall needs it). Add to the Manifest Editor:AddPermission(com.google.android.gms.permission.AD_ID) AddPermission(android.permission.ACCESS_NETWORK_STATE) AddManifestText( <queries> <package android:name="com.android.vending" /> <package android:name="com.farsitel.bazaar" /> <package android:name="ir.mservices.market" /> <package android:name="com.huawei.hwid" /> <package android:name="com.huawei.hms" /> <package android:name="com.huawei.hwid.tv" /> <intent><action android:name="android.intent.action.VIEW" /><data android:scheme="market" /></intent> <intent><action android:name="android.intent.action.VIEW" /><data android:scheme="bazaar" /></intent> <intent><action android:name="android.intent.action.VIEW" /><data android:scheme="myket" /></intent> <intent><action android:name="android.intent.action.VIEW" /><data android:scheme="http" /></intent> <intent><action android:name="android.intent.action.VIEW" /><data android:scheme="https" /></intent> </queries>)
Basic usage:
Sub Globals
Dim Adivery As Adivery
End Sub
Sub Activity_Create(FirstTime As Boolean)
Adivery.Initialize("YOUR_APP_ID")
Adivery.PrepareInterstitialAd("YOUR_PLACEMENT_ID")
End Sub
Sub On_Interstitial_Ad_Loaded(placement As String)
Adivery.Show(placement)
End Sub
Sub On_Error(placement As String, error As String)
Log(error)
End SubAdivery:
| Member | What it does |
|---|---|
Initialize(AppId As String) |
Configures the SDK. Call it first, from your main activity. |
SetLoggingEnabled(Enabled As Boolean) |
Turns the SDK's logging on or off. |
SetUserId(UserId As String) |
Identifies the user for server-side reward verification (sent as uid). |
IsLoaded(PlacementId As String) As Boolean |
Whether an ad is ready to show for that placement. |
AddListener(Name As String) / RemoveListener(Name As String) |
Also raise the calling activity's events to Subs named Name_On_.... |
| Format | Load | Show | Events (placement As String first) |
|---|---|---|---|
| Interstitial | PrepareInterstitialAd |
Show |
On_Interstitial_Ad_Loaded, _Shown, _Clicked, _Closed |
| Rewarded | PrepareRewardedAd |
Show |
On_Rewarded_Ad_Loaded, _Shown, _Clicked, and On_Rewarded_Ad_Closed(placement, reward As Boolean) |
| App Open | PrepareAppOpenAd |
ShowAppOpen |
On_App_Open_Ad_Loaded, _Shown, _Clicked, _Closed |
| Offer Wall | PrepareOfferWallAd |
Show |
On_Offer_Wall_Ad_Loaded, _Shown, _Clicked, _Closed, and On_Offer_Wall_Mission_Rewarded(placement, currency As String, amount As Int) |
Errors for every format arrive in On_Error(placement As String, error As String).
- Where events arrive.
Initializeraises events toOn_...Subs in the activity that called it.AddListener(Name)addsName_On_...Subs in the calling activity. Either way, an activity's Subs only run while it's in front. - Reloading. Interstitial, rewarded and App Open ads load the next ad by themselves after one closes.
- The Offer Wall needs v4.10.0-alpha.1 or later.
- Don't preload it: call
PrepareOfferWallAdwhen the user opens it, andShowit fromOn_Offer_Wall_Ad_Loaded. - It isn't loaded again after it closes, so prepare it each time.
On_Offer_Wall_Mission_Rewardedcan run several times per showing.
- Don't preload it: call
AdiveryBannerAd is a view. Initialize2(EventName, PlacementId, Size) loads it, with
Size one of BANNER, LARGE_BANNER, MEDIUM_RECTANGLE or SMART_BANNER. Add it to your
layout with Activity.AddView. It raises <EventName>_Ad_Loaded, <EventName>_Ad_Clicked
and <EventName>_Ad_Error(error As String):
Sub Globals
Dim Banner As AdiveryBannerAd
End Sub
Sub ShowBanner
Banner.Initialize2("MyBanner", "YOUR_PLACEMENT_ID", Banner.BANNER)
Activity.AddView(Banner, (100%x - 320dip) / 2, 100%y - 50dip, 320dip, 50dip)
End Sub
Sub MyBanner_Ad_Loaded
Log("banner loaded")
End Sub
Sub MyBanner_Ad_Error(error As String)
Log(error)
End SubB4A's LibraryCompiler only runs on Windows:
- Extract
classes.jarfrom the Adivery SDK'ssdk-X.Y.Z.aar(from Maven Central) intob4a-plugin/libs/.*.jaris gitignored. - Run
build.bat. It writesAdivery.jarandAdivery.xmlto B4A's Additional Libraries folder. - Copy
sdk-X.Y.Z.aarnext to them asAdivery.aarto run the sample.
Plugin versions track Adivery SDK versions: SDK X.Y.Z is release vX.Y.Z. The release zip
holds adivery-b4a/Adivery.{jar,xml,aar}. Two Claude Code skills cover the workflow:
new-plugin-versionsyncs the wrapper, sample and docs with a new SDK version.- It checks the Java against the published SDK and against the API customers already have.
- It hands the Windows rebuild to you, then verifies the jar you send back.
release-b4a-pluginpackages the zip and publishes the GitHub release.
Their helper scripts also run on their own. For example, bridge.py check checks the
wrapper, the sample and this README against an SDK AAR (see
.claude/skills/new-plugin-version/SKILL.md).