Android Question B4A 14.20 beta R8 - Google Play Billing and AdsHelper

asales

Expert
Licensed User
Longtime User
I got this errors when compile with:
#R8Optimizer: True

Google Play Billling
B4X:
b4xmainpage$ResumableSub_GetInventoryInformationresume (java line: 1517)
java.lang.RuntimeException: Method: getSubscriptionOfferDetails not found in: com.android.billingclient.api.n
    at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(SourceFile:172)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(SourceFile:11)
    at br.com.myprofiles.b4xmainpage$ResumableSub_GetInventoryInformation.resume(SourceFile:1517)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(SourceFile:45)
    at anywheresoftware.b4a.BA.raiseEvent2(SourceFile:68)
    at anywheresoftware.b4a.BA$2.run(SourceFile:129)
    at android.os.Handler.handleCallback(Handler.java:914)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:225)
    at android.app.ActivityThread.main(ActivityThread.java:7563)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:994)
Current time: 30/09/2026 12:19
b4xmainpage$ResumableSub_GetInventoryInformationresume (java line: 1517)
java.lang.RuntimeException: Method: getSubscriptionOfferDetails not found in: com.android.billingclient.api.n
    at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(SourceFile:172)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(SourceFile:11)
    at br.com.myprofiles.b4xmainpage$ResumableSub_GetInventoryInformation.resume(SourceFile:1517)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(SourceFile:45)
    at anywheresoftware.b4a.BA.raiseEvent2(SourceFile:68)
    at anywheresoftware.b4a.BA$2.run(SourceFile:129)
    at android.os.Handler.handleCallback(Handler.java:914)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:225)
    at android.app.ActivityThread.main(ActivityThread.java:7563)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:994)

AdsHelper
B4X:
*** page_main: B4XPage_Appear [mainpage]
(RuntimeException) java.lang.RuntimeException: Method: getConsentStatus not found in: x1.L
Consent information is being reset!
adshelper_vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv2 (java line: 17)
java.lang.RuntimeException: Method: reset not found in: x1.L
    at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(SourceFile:172)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(SourceFile:11)
    at br.com.myprofiles2.adshelper._vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv2(SourceFile:17)
    at br.com.myprofiles2.b4xmainpage$ResumableSub_CheckConsentAndAddAds.resume(SourceFile:85)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(SourceFile:45)
    at anywheresoftware.b4a.BA.raiseEvent2(SourceFile:68)
    at anywheresoftware.b4a.BA$1.run(SourceFile:103)
    at android.os.Handler.handleCallback(Handler.java:914)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:225)
    at android.app.ActivityThread.main(ActivityThread.java:7563)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:994)
adshelper_vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv2 (java line: 17)
 
Last edited:

asales

Expert
Licensed User
Longtime User
The Google Play Billing lib it seems to be correct.

But I get this errors bellow in the FirebaseAdmob2 with native ads and rewarded ads.
This problem could see check this example:

B4X:
RewardVideoAd_Rewarded
b4xpagerewardedvideo_rewardvideoad_rewarded (java line: 34)
java.lang.RuntimeException: Method: getAmount not found in: com.google.android.gms.internal.ads.ou
    at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(SourceFile:186)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(SourceFile:11)
    at admob.tests.b4xpagerewardedvideo._rewardvideoad_rewarded(SourceFile:34)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(SourceFile:106)
    at anywheresoftware.b4a.keywords.Common$12.run(SourceFile:59)
    at android.os.Handler.handleCallback(Handler.java:914)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:225)
    at android.app.ActivityThread.main(ActivityThread.java:7563)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:994)

B4X:
Native Ad initializing. This will be a test ad.
Trying to load unified native ad
mwfirebaseadmobnative$ResumableSub_LoadNativeAdresume (java line: 473)
java.lang.ClassNotFoundException: com.google.android.gms.ads$nativead$NativeAd$OnNativeAdLoadedListener
    at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(SourceFile:89)
    at anywheresoftware.b4j.object.JavaObject.createEvent(SourceFile:15)
    at anywheresoftware.b4j.object.JavaObject.CreateEventFromUI(SourceFile:7)
    at admob.tests.mwfirebaseadmobnative$ResumableSub_LoadNativeAd.resume(SourceFile:473)
    at admob.tests.mwfirebaseadmobnative._vvvvvvvvvvvvvv5(SourceFile:9)
    at admob.tests.b4xpagenative._b4xpage_created(SourceFile:68)
    at admob.tests.b4xpagenative.callSub(SourceFile:19)
    at anywheresoftware.b4a.keywords.Common.CallSub4(SourceFile:10)
    at anywheresoftware.b4a.keywords.Common.CallSubNew2(SourceFile:7)
    at admob.tests.b4xpagesmanager._vvvvvvvvvvvvvvvvvvvvvvvvv6(SourceFile:49)
    at admob.tests.b4xpagesmanager._vvv0(SourceFile:18)
    at admob.tests.b4xpages._vvv0(SourceFile:5)
    at admob.tests.b4xmainpage._pnlnative_click(SourceFile:5)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(SourceFile:106)
    at anywheresoftware.b4a.BA.raiseEvent(SourceFile:7)
 
Upvote 0

asales

Expert
Licensed User
Longtime User
It worked with rewarded ads, but in the native ads I'm getting this new error.
In default native ad without video works but in an app with video in the native ad I get the error.
B4X:
pagemain$ResumableSub_LoadNativeAdresume (java line: 924)
java.lang.RuntimeException: Method: getVideoController not found in: f2.R0
    at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(SourceFile:172)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(SourceFile:11)
    at br.com.myprofiles.pagemain$ResumableSub_LoadNativeAd.resume(SourceFile:924)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(SourceFile:45)
    at anywheresoftware.b4a.BA.raiseEvent2(SourceFile:68)
    at anywheresoftware.b4a.BA$1.run(SourceFile:103)
    at android.os.Handler.handleCallback(Handler.java:914)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:225)
    at android.app.ActivityThread.main(ActivityThread.java:7563)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:994)

Here the native ad sub:
B4X:
Sub LoadNativeAd(AdName As String, idAd As String, lay As String, wid As Int, heig As Int) As ResumableSub
    Dim AdUnitId As String = idAd

    Dim ctxt As JavaObject
    ctxt.InitializeContext

    Dim builder As JavaObject
    builder.InitializeNewInstance("com.google.android.gms.ads.AdLoader.Builder", Array(ctxt, AdUnitId))

    '*** Code changed
    Dim onUnifiedAdLoadedListener As Object = builder.CreateEventFromUI("com/google/android/gms/ads/nativead/NativeAd.OnNativeAdLoadedListener".Replace("/", "."), _
       "UnifiedAdLoaded", Null)
    builder.RunMethod("forNativeAd", Array(onUnifiedAdLoadedListener))
    '*** End Code changed
 
    Dim Listener As JavaObject
    Listener.InitializeNewInstance(Application.PackageName & ".main$MyAdListener", Array(AdName))  'change 'main' with the current activity module name
    builder.RunMethod("withAdListener", Array(Listener))
   
    Dim AdLoader As JavaObject = builder.RunMethod("build", Null)

'    Sends a request To AdMob, requesting an ad.
    Dim AdRequestBuilder As JavaObject
    AdRequestBuilder.InitializeNewInstance("com/google/android/gms/ads/AdRequest.Builder".Replace("/", "."), Null)
    AdLoader.RunMethod("loadAd", Array(AdRequestBuilder.RunMethod("build", Null)))

    Wait For (builder) UnifiedAdLoaded_Event (MethodName As String, Args() As Object)
   
    Dim NativeAdView As JavaObject    '*** Code changed
   
    NativeAdView.InitializeNewInstance("com/google/android/gms/ads/nativead/NativeAdView".Replace("/", "."), Array(ctxt))
             
    'painel do anúncio
    Dim pNativeAdView As B4XView = xui.CreatePanel("")  '21/11/24
    pNativeAdView = NativeAdView
   
    Dim NativeAd As JavaObject
    If Args <> Null Then
        NativeAd = Args(0)
    Else      
        Return pNativeAdView
    End If

    Dim content As B4XView = xui.CreatePanel("")  '21/11/24
    content.SetLayoutAnimated(0, 0, 0, 100%x, 100%y)
    content.LoadLayout(lay)
    pNativeAdView.AddView(content, 0, 0, wid, heig)
   
    Dim pAdmob2 As Panel
    pAdmob2 = content.GetView(0)

    Dim lblAd As Label = pAdmob2.GetView(0)
    lblAd.Visible = True
   
    Dim lbl As Label = pAdmob2.GetView(2)
    lbl.Text = NativeAd.RunMethod("getHeadline", Null)
    NativeAdView.RunMethod("setHeadlineView", Array(lbl))
   
    Dim lbl2 As Label = pAdmob2.GetView(3)
    lbl2.Text = NativeAd.RunMethod("getBody", Null)
    NativeAdView.RunMethod("setBodyView", Array(lbl2))

    Try
        Dim logo As JavaObject = NativeAd.RunMethod("getIcon", Null)
        If logo.IsInitialized Then
            Dim logoView As Panel = pAdmob2.GetView(1)
            logoView.Background = logo.RunMethod("getDrawable", Null)
            NativeAdView.RunMethod("setIconView", Array(logoView))
        Else  'exibe imagem se não existir logotipo 05/11/18
            Dim images As List = NativeAd.RunMethod("getImages", Null)
            If images.IsInitialized And images.Size > 0 Then
                Dim logoView As Panel = pAdmob2.GetView(1)
                Dim image As JavaObject = images.Get(0)
                logoView.Background = image.RunMethod("getDrawable", Null)
                NativeAdView.RunMethod("setImageView", Array(logoView))
            End If
        End If
    Catch
        Log(LastException)
    End Try
   
    '*** Code changed
    Dim MediaContent As JavaObject = NativeAd.RunMethod("getMediaContent", Null)
    If MediaContent.IsInitialized Then
        Dim vid As JavaObject = MediaContent.RunMethod("getVideoController", Null)  'movido da linha abaixo
    End If
    '*** End Code changed
   
    'só exibe imagem grande/vídeo se layout for = 250dip
    If lay = "layadmob250" Then
        Dim hasvid As Boolean = vid.RunMethod("hasVideoContent", Null)
        If Funcoes.Check_Device_Developer Then Log("(DEV) hasvid: " & hasvid)
        Dim pImg As Panel = pAdmob2.GetView(5)
        Dim MediaView As JavaObject
        MediaView.InitializeNewInstance("com/google/android/gms/ads/nativead/MediaView".Replace("/", "."), Array(ctxt))  '*** Code changed
       
        Dim esq As Int
        esq = (pAdmob2.Width / 2) - 150dip
        content.AddView(MediaView, esq, pImg.top, 300dip, 130dip)
        NativeAdView.RunMethod("setMediaView", Array(MediaView))
           
        '*** price
        If Funcoes.IsNull(NativeAd.RunMethod("getPrice", Null)) = False Then
            Dim pr As String = NativeAd.RunMethod("getPrice", Null)
            If (Funcoes.IsNull(pr) = False) And (pr.ToLowerCase <> "null") Then
                Dim lblPrice As Label = pAdmob2.GetView(6)
                lblPrice.Text = pr
            End If
        End If
   
'    You can assign Null To variables that work by reference, all numeric variables Or basic variables work by value And Not by reference
'    Objects, classes, Or non-basic variables work As references And can be assigned with Null
   
        '*** rating
        Dim sr As Float = 0
        If Funcoes.IsNull(NativeAd.RunMethod("getStarRating", Null)) = False Then
            Dim sr As Float = NativeAd.RunMethod("getStarRating", Null)
            If sr > 3 Then
                Dim i As Int
                i = Floor(sr)
                Dim lblStars As Label = pAdmob2.GetView(7)
                lblStars.Text = Funcoes.StarsLabel(i, Colors.RGB(255,165,0))
            End If
        End If
    End If
   
    '*** button to action
    Dim btAction As Button = pAdmob2.GetView(4)
    Dim cd As ColorDrawable
    cd.Initialize(Colors.RGB(0,180,0),6dip)  'verde escuro
    btAction.Background = cd
    btAction.TextColor = Colors.White
    btAction.Typeface = Typeface.DEFAULT_BOLD
    btAction.Text = NativeAd.RunMethod("getCallToAction", Null)
    NativeAdView.RunMethod("setCallToActionView", Array(btAction))
   
    NativeAdView.RunMethod("setNativeAd", Array(NativeAd))

    Return pNativeAdView
End Sub
 
Upvote 0

asales

Expert
Licensed User
Longtime User
Solved with this tip and help of ChatGPT to add this rule:
B4X:
AddProguardText(
    -keep class com.google.android.gms.ads.** { *; }
    -keep interface com.google.android.gms.ads.** { *; }
)
 
Upvote 1
Top