Java Question Facebook Audience libraries

hanyelmehy

Active Member
Licensed User
Longtime User
i try to create libraries for Facebook Audience Interstitial Ads with this code
B4X:
package b4a.facebookaudi;


import com.facebook.ads.*;

import android.R;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.Toast;


import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.DontInheritEvents;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.objects.ViewWrapper;

@SuppressWarnings("unused")
@Version(1.0f)
@ShortName("FaceBookAudi")
@Events(values={"adLoaded", "IntAdError (ErrorCode As String)",
      "AdScreenDismissed", "error"})
@ActivityObject
@DontInheritEvents
@Permissions(values={"android.permission.INTERNET", "android.permission.ACCESS_NETWORK_STATE"})
@DependsOn(values={"AudienceNetwork.aar","DebugSettings.aar","com.android.support:support-v4"}) //


public class FacebookAudi extends ViewWrapper<AdView> {
    private InterstitialAd interstitialAd;
    private String eventName;
    private BA ba;
    private AdView adView;
    public static Object SIZE_320 = AdSize.BANNER_320_50;
    public static Object SIZE_H50 = AdSize.BANNER_HEIGHT_50;
    public static Object SIZE_H90 = AdSize.BANNER_HEIGHT_90;
    public static Object SIZE_RH250 = AdSize.RECTANGLE_HEIGHT_250;
    
        
    public void InterstitialAd(final BA ba,String PublisherId,String EventName) {
        this.ba = ba;
        eventName = EventName.toLowerCase(BA.cul);
        interstitialAd = new InterstitialAd(ba.context, PublisherId);
        
          interstitialAd.setAdListener(new InterstitialAdListener() {
          @Override
          public void onInterstitialDisplayed(Ad ad) {
            // Interstitial displayed callback
          }

          @Override
          public void onInterstitialDismissed(Ad ad) {
            // Interstitial dismissed callback
          }

          @Override
          public void onError(Ad ad, AdError adError) {
            // Ad error callback
            //Toast.makeText(MainActivity.this, "Error: " + adError.getErrorMessage(),
            //Toast.LENGTH_LONG).show();
          }

          @Override
          public void onAdLoaded(Ad ad) {
            // Show the ad when it's done loading.
            ba.raiseEvent(this, eventName + "_adLoaded"); 
            interstitialAd.show();               
          }

          @Override
          public void onAdClicked(Ad ad) {
            // Ad clicked callback
          }

          @Override
          public void onLoggingImpression(Ad ad) {
            // Ad impression logged callback       
          }
        });

        // For auto play video ads, it's recommended to load the ad
        // at least 30 seconds before it is shown
        interstitialAd.loadAd();
      }

interstitialAd.loadAd work fine and send request but when call interstitialAd.show i get this error
B4X:
java.lang.NoClassDefFoundError: com.facebook.ads.internal.view.b.e
    at com.facebook.ads.internal.view.b.d.a(Unknown Source)
    at com.facebook.ads.internal.view.b.d.<init>(Unknown Source)
    at com.facebook.ads.internal.view.b.b.<init>(Unknown Source)
    at com.facebook.ads.internal.view.o.<init>(Unknown Source)
    at com.facebook.ads.internal.view.n.<init>(Unknown Source)
    at com.facebook.ads.internal.adapters.l$3.a(Unknown Source)
    at com.facebook.ads.internal.adapters.l$3.a(Unknown Source)
    at com.facebook.ads.internal.c.b$1$2.run(Unknown Source)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5551)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is not related to this error but wrapper objects (that extend ViewWrapper or AbsObjectWrapper) should never have non-static member variables.
I don't think that you need those variables here.

The error itself happens because you are missing a dependency. Open the jar file that is inside AudienceNetwork.aar with 7zip. Do you see the missing class there?
 

hanyelmehy

Active Member
Licensed User
Longtime User
It is not related to this error but wrapper objects (that extend ViewWrapper or AbsObjectWrapper) should never have non-static member variables.
I don't think that you need those variables here.

The error itself happens because you are missing a dependency. Open the jar file that is inside AudienceNetwork.aar with 7zip. Do you see the missing class there?
if i understand ,i open classes.jar founded in AudienceNetwork.aar with 7zip and i can found e.class under ads\internal\view\b\
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It should be com\facebook\ads\internal\view\b\e.class
I guess that it is there.

Add these lines:
B4X:
#AdditionalJar: com.android.support:appcompat-v7
#AdditionalJar: com.android.support:recyclerview-v7
#AdditionalJar: com.android.support:support-annotations
#AdditionalJar: com.google.android.gms:play-services-ads

Add a reference to ExoPlayer library.

Where does it come from?
Here:
http://central.maven.org/maven2/com...rk-sdk/4.27.0/audience-network-sdk-4.27.0.pom
 
Top