Android Question Adview inline and R8

asales

Expert
Licensed User
Longtime User
I use this code below to get a height of a banner inline used in a customlist view.

Compiling using R8 I got this error:
java.lang.RuntimeException: Method: getAdSize not found in: com.google.android.gms.ads.g
at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(SourceFile:172)


And using this suggestion by Gemini is fixed:
B4X:
AddProguardText(
-keep class com.google.android.gms.ads.** { *; }
-keep interface com.google.android.gms.ads.** { *; }
)

I don't know if @Erel needs to change anything in the Admob lib, but I share this rules to anyone was needed.

B4X:
Sub Adv1_ReceiveAd
    Dim ctxt As JavaObject
    ctxt.InitializeContext

    ' Obtém o objeto nativo do AdView através de JavaObject
    Dim adJo As JavaObject = AdViewInline
    Dim currentAdSize As JavaObject = adJo.RunMethod("getAdSize", Null)

    If currentAdSize.IsInitialized Then
        Dim realHeight As Int = currentAdSize.RunMethod("getHeightInPixels", Array(ctxt))
        LogColor("Altura real após carregar: " & realHeight, xui.Color_Magenta)

        'If you need to dynamically update the item's height in the CLV:
        '1. Locate the item's index where the listing is located.
        '2. Resize the panel and update the CLV with clvHome.ResizeItem
    End If
End Sub
 
Back
Top