Git Product home page Git Product logo

mopub-flutter's Introduction

MoPub SDK for Flutter

Note - When running the example repo, please make sure to add your GADIdentifier as well as your AppLovin Key to use MoPub mediation, alternatively you can remove these from your Manifest, not doing so may result in crashes.

Getting started:

1. Initialise MoPub

Call Mopub.init() in the initState() of your app

try {
      MoPub.init('ad_unit_id', testMode: true).then((_) {
        _loadRewardedAd();
        _loadInterstitialAd();
      });
    } on PlatformException {}

2. To load a rewarded ad

void _loadRewardedAd() {
   videoAd = MoPubRewardedVideoAd('ad_unit_id',
       (result, args) {
     setState(() {
       rewardedResult = '${result.toString()}____$args';
     });
     print('$result');
     if (result == RewardedVideoAdResult.GRANT_REWARD) {
       print('Grant reward: $args');
     }
   }, reloadOnClosed: true);
 }

3. To load an interstitial ad

 void _loadInterstitialAd() {
  interstitialAd = MoPubInterstitialAd(
    'ad_unit_id',
    (result, args) {
      print('Interstitial $result');
    },
    reloadOnClosed: true,
  );    
}

4. To call a banner ad

 MoPubBannerAd(
            adUnitId: 'ad_unit_id',
            bannerSize: BannerSize.STANDARD,
            keepAlive: true,
            listener: (result, dynamic) {
              print('$result');
            },
          );

IMPORTANT: If you’re Publishing and using Proguard:

# Keep public classes and methods.
-keepclassmembers class com.mopub.** { public *; }
-keep public class com.mopub.**
-keep public class android.webkit.JavascriptInterface {}

# Explicitly keep any BaseAd and CustomEventNative classes in any package.
-keep class * extends com.mopub.mobileads.BaseAd {}
-keep class * extends com.mopub.nativeads.CustomEventNative {}

# Keep methods that are accessed via reflection
-keepclassmembers class ** { @com.mopub.common.util.ReflectionTarget *; }

-keep class com.google.android.gms.common.GooglePlayServicesUtil {*;}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient {*;}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info {*;}

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}        

mopub-flutter's People

Contributors

brunokum avatar nitoba avatar

Watchers

James Cloos avatar Alexandre Tolstenko avatar Fabiano de Santana avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.