Get Started with Avocarrot

Overview

Examples

Android

Overview

- Avocarrot Exchange SDK

Setup Exchange SDK

Stream

Native Assets

Exchange Troubleshooting

- Avocarrot Mediation SDK

Setup Mediation

Stream Ads Mediation

Native ads Mediation

Native Assets Mediation

Banner Mediation

Interstitial Mediation

Video Mediation

Supported Networks & Ad Types

Mediation Troubleshooting

iOS

Overview

- Avocarrot Exchange SDK

Setup SDK

Stream

Native Assets

Exchange Troubleshooting

- Avocarrot Mediation

Getting Started With Mediation

Stream Ads Mediation

Native Ads Mediation

Banner Ads Mediation

Interstitial Ads Mediation

Video Ads Mediation

Supported Networks & Ad Types

Mediation Troubleshooting

API Documentation

Reporting API

Help

FAQ

Updates

SDK Change Log

Android Change Log

iOS Change Log

Migrate from 3.x to Android SDK 4.5.x

Updated 8 days ago ​by Nikos Tsiougkos

Overview

This guide will help you migrate from Avocarrot Android SDK  v3.x to Avocarrot Android SDK v4.5.x. This concerns only existing Avocarrot publishers that are currently using SDK v3.x.

Terminology Changes

Old version (v3.x)New version (v4.5.x)
Feed/List/InstreamStream
AvocarrotInstreamStreamAdBaseAdapter
AvocarrotInstreamRecyclerViewStreamAdRecyclerAdapter
NaturalPause / AvocarrotInterstitialNativeAd with FullscreenNativeAdView
AvocarrotCustomNativeAssetsAd
CustomModelNativeAssets
SandboxTest mode

Install Avocarrot SDK

Update your build.gradle to use the latest Avocarrot SDK

dependencies {
...
    compile('com.avocarrot:android-sdk:4.5.+')
...
}


Old version (v3.x)New version  (v4.5.x)
AvocarrotInstream avocarrotInstream = 
   new AvocarrotInstream(
      <yourAdapter>,
      this, /* Context */
      "<your API Key>",
      "<your Ad unit id (Placement Key)>"
   );
avocarrotInstream.setLogger(true, "ALL");
avocarrotInstream.setSandbox(true);
<yourListView>.setAdapter(avocarrotInstream);
Avocarrot.setTestMode(true); // enable test ads
Avocarrot.setDebugMode(true); // enable logger
StreamAdBaseAdapter adAdapter = 
   new StreamAdBaseAdapter.Builder()
       .setAdapter(<yourAdapter>)
       .setAdUnitId(<your adUnitId>)
       .setViewBuilder(DynamicNativeAdView.BUILDER)
       .build(this /* Context */ );
<yourListView>.setAdapter(adAdapter);
adAdapter.loadAd();
AvocarrotInstreamRecyclerView avocarrotInstreamRecyclerView = 
new AvocarrotInstreamRecyclerView(
   <yourAdapter>,
   this, /* Context */
   "<your API Key>",
   "<your Ad unit id (Placement Key)>"
 );
avocarrotInstreamRecyclerView.setLogger(true, "ALL");
avocarrotInstreamRecyclerView.setSandbox(true);
<yourRecyclerView>.setLayoutManager( new LinearLayoutManager(this) );
<yourRecyclerView>.setAdapter(avocarrotInstreamRecyclerView);
<yourRecyclerView>.setLayoutManager( new LinearLayoutManager(this) );
Avocarrot.setTestMode(true); // enable test ads
Avocarrot.setDebugMode(true); // enable logger
StreamAdRecyclerAdapter adAdapter = 
   new StreamAdRecyclerAdapter.Builder()
       .setAdapter(<yourAdapter>)
       .setAdUnitId(<your adUnitId>)
       .setViewBuilder(DynamicNativeAdView.BUILDER)
       .build(this /* Context */ );
<yourRecyclerView>.setAdapter(adAdapter);
adAdapter.loadAd();

Interstitial

Old version (v3.x)New version (v4.5.x)
AvocarrotInterstitial avocarrotInterstitial =   
    new AvocarrotInterstitial(      
        this, /* Activity */      
        "<your API Key>",      
        "<your Ad unit id (Placement Key)>"   
    ); 
avocarrotInterstitial.setLogger(true, "ALL"); 
avocarrotInterstitial.setSandbox(true); 
avocarrotInterstitial.loadAndShowAd();
Avocarrot.setTestMode(true); // enable test ads
Avocarrot.setDebugMode(true); // enable logger
NativeAdPool
   .load(this /* Activity */,
         <your adUnitId>,
         FullscreenNativeAdView.BUILDER,
         null,
         new NativeAdCallback() {
            @Override
            public void onAdLoaded(@NonNull NativeAd ad) {
                ad.renderAdView();
            }
            @Override
            public void onAdFailed(@NonNull NativeAd ad, 
                                   @NonNull ResponseStatus responseStatus) {}
            @Override
            public void onAdOpened(@NonNull NativeAd ad) {}
            @Override
            public void onAdClicked(@NonNull NativeAd ad) {}
            @Override
            public void onAdClosed(@NonNull NativeAd ad) {}
            @Override
            public void onAdCompleted(@NonNull NativeAd ad) {}
        }
    )
   .reloadAd();

Native Assets

Old version (v3.x)New version (v4.x)
final AvocarrotCustom avocarrotCustom =
      new AvocarrotCustom(
         this, /* Activity */
         "<your API Key>",
         "<your Ad unit id (Placement Key)>"
      );
avocarrotCustom.setLogger(true, "ALL");
avocarrotCustom.setSandbox(true);
avocarrotCustom.setListener(
   new AvocarrotCustomListener() {
      @Override
      public void onAdLoaded(List<CustomModel> ads) {
         super.onAdLoaded(ads);
         if ((ads==null) || (ads.size()<1)){
            return;
         }
         final CustomModel ad = ads.get(0);
         ViewGroup container = ...;
         TextView title = ...;
         ImageView imageView = ...;
         ImageView iconView = ...;
         Button button = ...;
         com.avocarrot.androidsdk.VideoView videoView = ...;
         com.avocarrot.androidsdk.ui.AdChoicesView adChoicesView = ...;
         
         title.setText(ad.getTitle());
         button.setText(ad.getCTAText());
         avocarrotCustom.loadIcon(ad, iconView);
         avocarrotCustom.loadImage(ad, imageView);
         avocarrotCustom.loadMedia(ad, imageView, videoView);
         avocarrotCustom.bindView(ad, container, adChoicesView);
         button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               avocarrotCustom.handleClick(ad);
            }
         });
      }
  });
  avocarrotCustom.loadAd();
Avocarrot.setTestMode(true); // enable test ads
Avocarrot.setDebugMode(true); // enable logger
final NativeAssetsConfig.Builder config = 
    new NativeAssetsConfig.Builder()
        .prefetchIcon(true)
        .prefetchImage(true)
        .prefetchAdChoiceIcon(true);
NativeAssetsAdCallback nativeAssetsAdCallback = new NativeAssetsAdCallback() {
    @Override
    public void onAdLoaded(@NonNull NativeAssetsAd nativeAssetsAd, @NonNull NativeAssets nativeAssets) {
        final View adContainer = ...
        final List clickableViews = new ArrayList<>();
        final TextView titleView = ...
        final TextView bodyView = ...
        final ImageView iconView = ...
        final ImageView imageView = ...
        final TextView ctaView = ...
        final ImageView adChoiceImageView = ...
        final TextView adChoiceTextView = ...
        if (titleView != null) {
            titleView.setText(nativeAssets.getTitle());
            clickableViews.add(titleView);
        }
        if (bodyView != null) {
            bodyView.setText(nativeAssets.getText());
        }
        if (iconView != null) {
            iconView.setImageDrawable(nativeAssets.getIcon().getDrawable());
            clickableViews.add(iconView);
        }
        if (imageView != null) {
            imageView.setImageDrawable(nativeAssets.getImage().getDrawable());
            clickableViews.add(imageView);
        }
        if (ctaView != null) {
            ctaView.setText(nativeAssets.getCallToAction());
            clickableViews.add(ctaView);
        }
        final AdChoice adChoice = nativeAssets.getAdChoice();
        if (adChoice != null) {
            if (adChoiceImageView != null) {
                adChoiceImageView.setImageDrawable(adChoice.getIcon().getDrawable());
                nativeAssetsAd.registerAdChoiceViewForClick(adChoiceImageView);
            }
            if (adChoiceTextView != null) {
                adChoiceTextView.setText(adChoice.getIconCaption());
                nativeAssetsAd.registerAdChoiceViewForClick(adChoiceTextView);
            }
        } else {
            adChoiceImageView.setImageDrawable(null);
            adChoiceTextView.setText(null);
        }
        nativeAssetsAd.registerViewsForClick(clickableViews);
        nativeAssetsAd.registerViewForImpression(adContainer);
    }
    @Override
    public void onAdFailed(@NonNull NativeAssetsAd nativeAssetsAd, @NonNull ResponseStatus responseStatus) {}
    @Override
    public void onAdOpened(@NonNull NativeAssetsAd nativeAssetsAd) {}
    @Override
    public void onAdClicked(@NonNull NativeAssetsAd nativeAssetsAd) {}
};
NativeAssetsAdPool
        .load(this, <your adUnitId>, config, nativeAssetsAdCallback)
        .reloadAd();

Mopub Adapter

You can migrate Mopub  Avocarrot Adapter using these links :

1) Update the Avocarrot Adapter


2) Add AdUnitId in CustomEventClassData of the Mopub Dashboard :

Old version (v3.x)New version (v4.x)
{
   "apiKey":"<Avocarrot ApiKey>",
   "placementKey":"<Avocarrot AdUnitId>"
}
{
   "apiKey":"<Avocarrot ApiKey>",
   "placementKey":"<Avocarrot AdUnitId>",
   "adUnitId":"<Avocarrot adUnitId>"
}

Keep apiKey and placementKey for users that have the old SDK

If you encounter any issues during the migration or you need further assistance please contact us at Support or through your dashboard chat.

Was this article useful?