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 4.0.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  v4.0.x to Avocarrot Android SDK v4.5.x. This concerns only existing Avocarrot publishers that are currently using SDK v4.0.x.

Terminology Changes

Old version (v4.0.x)New version (v4.5.x)
Sandbox
Test mode

Install Avocarrot SDK

Update your build.gradle to use the latest Avocarrot SDK

dependencies {
...
    compile('com.avocarrot:android-sdk:4.5.+')
...
}
Old version (v4.0.x)New version  (v4.5.x)
<yourListView>.setAdapter(
   Avocarrot.build(
      this /* Context */,
      new StreamAdBaseAdapter.Configuration.Builder()
         .setAdapter(<yourAdapter>)
         .setApiKey(<your api key>)
         .setAdUnitId(<your adUnitId)
         .setLogLevel(Level.DEBUG)
         .setSandbox(true)
   )
);
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();
<yourRecyclerView>.setLayoutManager( new LinearLayoutManager(this) );
<yourRecyclerView>.setAdapter(
   Avocarrot.build(
      this /* Context */,
      new StreamAdRecyclerAdapter.Configuration.Builder()
         .setAdapter(<yourAdapter>)
         .setApiKey(<your API Key>)
         .setAdUnitId(<your adUnitId>)
         .setLogLevel(Level.DEBUG)
         .setSandbox(true)
   )
);
<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 (v4.0.x)New version (v4.5.x)
Avocarrot.build(   
    this /* Activity */,   
    new InterstitialAd.Configuration.Builder()
      .setApiKey("<your API Key>")      
      .setAdUnitId("<your Ad unit id>")
      .setLogLevel(Level.DEBUG)
      .setSandbox(true)
).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 (v4.0.x)New version (v4.x)
    
Avocarrot.build(
   this /* Activity */,
   new NativeAssetsAd.Configuration.Builder()
      .setApiKey(<your API Key>)
      .setAdUnitId(<your Ad unit id>)
      .setLogLevel(Level.DEBUG)
      .setSandbox(true)
      .setCallback(new NativeAssetsAdCallback() {
         @Override
         public void onAdLoaded(@NonNull final NativeAssetsAd nativeAssetsAd, @NonNull final List<NativeAssets> ads) {
            super.onAdLoaded(nativeAssetsAd, ads);
            if (ads.size() == 0) {
               return;
            }
            final NativeAssets ad = ads.get(0);
            View adContainer = ...
            TextView title = ...
            TextView text = ...
            Button callTo_Action = ...
            ImageView icon = ...
            RelativeLayout mediaContainer ...
            ImageView adChoices = ...
      
            AdLayout adLayout = 
               new AdLayout.BuilderWithView(adContainer)
                   .setTitle(title)
                   .setText(text)
                   .setCallToAction(callTo_Action)
                   .setIcon(icon)
                   .setMediaContainer(mediaContainer)
                   .setAdChoices(adChoices)
                   .addClickableView(title)
                   .addClickableView(callTo_Action)
                   .build();
      
            nativeAssetsAd.bindView(adLayout, ad);
         }
   })
).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 (v4.0.x)New version (v4.x)
{
   "apiKey":"<Avocarrot ApiKey>",
   "placementKey":"<Avocarrot AdUnitId>",
   "adUnitId":"<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?