diff --git a/packages/firebase_admob/CHANGELOG.md b/packages/firebase_admob/CHANGELOG.md index 6423b653bdd2..9b16c5e7c762 100644 --- a/packages/firebase_admob/CHANGELOG.md +++ b/packages/firebase_admob/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.9.0+7 + +* Update Android gradle plugin, gradle, and Admob versions. +* Improvements to the Android implementation, fixing warnings about a possible null pointer exception. +* Fixed an issue where an advertisement could incorrectly remain displayed when transitioning to another screen. + ## 0.9.0+6 * Remove duplicate example from documentation. diff --git a/packages/firebase_admob/android/build.gradle b/packages/firebase_admob/android/build.gradle index 846ec4851ca3..5dad775e1bab 100644 --- a/packages/firebase_admob/android/build.gradle +++ b/packages/firebase_admob/android/build.gradle @@ -21,7 +21,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.3.0' + classpath 'com.android.tools.build:gradle:3.4.2' } } @@ -45,6 +45,6 @@ android { disable 'InvalidPackage' } dependencies { - api 'com.google.firebase:firebase-ads:17.2.0' + api 'com.google.firebase:firebase-ads:18.1.1' } } diff --git a/packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/AdRequestBuilderFactory.java b/packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/AdRequestBuilderFactory.java index 9703241655c6..db92a7879401 100644 --- a/packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/AdRequestBuilderFactory.java +++ b/packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/AdRequestBuilderFactory.java @@ -10,6 +10,7 @@ import com.google.android.gms.ads.AdRequest; import java.util.ArrayList; import java.util.Date; +import java.util.List; import java.util.Map; class AdRequestBuilderFactory { @@ -53,21 +54,20 @@ private Integer getTargetingInfoInteger(String key, Object value) { return (Integer) value; } - private ArrayList getTargetingInfoArrayList(String key, Object value) { + private List getTargetingInfoArrayList(String key, Object value) { if (value == null) return null; if (!(value instanceof ArrayList)) { Log.w(TAG, "targeting info " + key + ": expected an ArrayList"); return null; } - return (ArrayList) value; + return (List) value; } AdRequest.Builder createAdRequestBuilder() { AdRequest.Builder builder = new AdRequest.Builder(); if (targetingInfo == null) return builder; - ArrayList testDevices = - getTargetingInfoArrayList("testDevices", targetingInfo.get("testDevices")); + List testDevices = getTargetingInfoArrayList("testDevices", targetingInfo.get("testDevices")); if (testDevices != null) { for (Object deviceValue : testDevices) { String device = getTargetingInfoString("testDevices element", deviceValue); @@ -75,7 +75,7 @@ AdRequest.Builder createAdRequestBuilder() { } } - ArrayList keywords = getTargetingInfoArrayList("keywords", targetingInfo.get("keywords")); + List keywords = getTargetingInfoArrayList("keywords", targetingInfo.get("keywords")); if (keywords != null) { for (Object keywordValue : keywords) { String keyword = getTargetingInfoString("keywords element", keywordValue); diff --git a/packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/FirebaseAdMobPlugin.java b/packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/FirebaseAdMobPlugin.java index 62e6fe4befeb..dd058a3e3bc0 100644 --- a/packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/FirebaseAdMobPlugin.java +++ b/packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/FirebaseAdMobPlugin.java @@ -14,6 +14,7 @@ import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugin.common.MethodChannel.Result; import io.flutter.plugin.common.PluginRegistry.Registrar; +import java.util.Locale; import java.util.Map; public class FirebaseAdMobPlugin implements MethodCallHandler { @@ -51,34 +52,41 @@ private void callInitialize(MethodCall call, Result result) { result.success(Boolean.TRUE); } - private void callLoadBannerAd( - int id, Activity activity, MethodChannel channel, MethodCall call, Result result) { + private void callLoadBannerAd(Integer id, Activity activity, MethodCall call, Result result) { String adUnitId = call.argument("adUnitId"); if (adUnitId == null || adUnitId.isEmpty()) { result.error("no_unit_id", "a null or empty adUnitId was provided for ad id=" + id, null); return; } - int width = call.argument("width"); - int height = call.argument("height"); - String adSizeType = call.argument("adSizeType"); + final Integer width = call.argument("width"); + final Integer height = call.argument("height"); + final String adSizeType = call.argument("adSizeType"); - if (!adSizeType.equals("AdSizeType.WidthAndHeight") - && !adSizeType.equals("AdSizeType.SmartBanner")) { + if (!"AdSizeType.WidthAndHeight".equals(adSizeType) + && !"AdSizeType.SmartBanner".equals(adSizeType)) { String errMsg = - String.format("an invalid adSizeType (%s) was provided for banner id=%d", adSizeType, id); + String.format( + Locale.ENGLISH, + "an invalid adSizeType (%s) was provided for banner id=%d", + adSizeType, + id); result.error("invalid_adsizetype", errMsg, null); } - if (adSizeType.equals("AdSizeType.WidthAndHeight") && (width <= 0 || height <= 0)) { + if ("AdSizeType.WidthAndHeight".equals(adSizeType) && (width <= 0 || height <= 0)) { String errMsg = String.format( - "an invalid AdSize (%d, %d) was provided for banner id=%d", width, height, id); + Locale.ENGLISH, + "an invalid AdSize (%d, %d) was provided for banner id=%d", + width, + height, + id); result.error("invalid_adsize", errMsg, null); } AdSize adSize; - if (adSizeType.equals("AdSizeType.SmartBanner")) { + if ("AdSizeType.SmartBanner".equals(adSizeType)) { adSize = AdSize.SMART_BANNER; } else { adSize = new AdSize(width, height); @@ -142,28 +150,30 @@ private void callLoadRewardedVideoAd(MethodCall call, Result result) { result.success(Boolean.TRUE); } - private void callShowAd(int id, MethodCall call, Result result) { + private void callShowAd(Integer id, MethodCall call, Result result) { MobileAd ad = MobileAd.getAdForId(id); if (ad == null) { result.error("ad_not_loaded", "show failed, the specified ad was not loaded id=" + id, null); return; } - if (call.argument("anchorOffset") != null) { - ad.anchorOffset = Double.parseDouble((String) call.argument("anchorOffset")); + final String anchorOffset = call.argument("anchorOffset"); + final String horizontalCenterOffset = call.argument("horizontalCenterOffset"); + final String anchorType = call.argument("anchorType"); + if (anchorOffset != null) { + ad.anchorOffset = Double.parseDouble(anchorOffset); } - if (call.argument("horizontalCenterOffset") != null) { - ad.horizontalCenterOffset = - Double.parseDouble((String) call.argument("horizontalCenterOffset")); + if (anchorType != null) { + ad.horizontalCenterOffset = Double.parseDouble(horizontalCenterOffset); } - if (call.argument("anchorType") != null) { - ad.anchorType = call.argument("anchorType").equals("bottom") ? Gravity.BOTTOM : Gravity.TOP; + if (anchorType != null) { + ad.anchorType = "bottom".equals(anchorType) ? Gravity.BOTTOM : Gravity.TOP; } ad.show(); result.success(Boolean.TRUE); } - private void callIsAdLoaded(int id, MethodCall call, Result result) { + private void callIsAdLoaded(Integer id, Result result) { MobileAd ad = MobileAd.getAdForId(id); if (ad == null) { result.error("no_ad_for_id", "isAdLoaded failed, no add exists for id=" + id, null); @@ -172,7 +182,7 @@ private void callIsAdLoaded(int id, MethodCall call, Result result) { result.success(ad.status == MobileAd.Status.LOADED ? Boolean.TRUE : Boolean.FALSE); } - private void callShowRewardedVideoAd(MethodCall call, Result result) { + private void callShowRewardedVideoAd(Result result) { if (rewardedWrapper.getStatus() == RewardedVideoAdWrapper.Status.LOADED) { rewardedWrapper.show(); result.success(Boolean.TRUE); @@ -181,7 +191,7 @@ private void callShowRewardedVideoAd(MethodCall call, Result result) { } } - private void callDisposeAd(int id, MethodCall call, Result result) { + private void callDisposeAd(Integer id, Result result) { MobileAd ad = MobileAd.getAdForId(id); if (ad == null) { result.error("no_ad_for_id", "dispose failed, no add exists for id=" + id, null); @@ -194,10 +204,6 @@ private void callDisposeAd(int id, MethodCall call, Result result) { @Override public void onMethodCall(MethodCall call, Result result) { - if (call.method.equals("initialize")) { - callInitialize(call, result); - return; - } Activity activity = registrar.activity(); if (activity == null) { @@ -208,8 +214,11 @@ public void onMethodCall(MethodCall call, Result result) { Integer id = call.argument("id"); switch (call.method) { + case "initialize": + callInitialize(call, result); + break; case "loadBannerAd": - callLoadBannerAd(id, activity, channel, call, result); + callLoadBannerAd(id, activity, call, result); break; case "loadInterstitialAd": callLoadInterstitialAd(MobileAd.createInterstitial(id, activity, channel), call, result); @@ -221,13 +230,13 @@ public void onMethodCall(MethodCall call, Result result) { callShowAd(id, call, result); break; case "showRewardedVideoAd": - callShowRewardedVideoAd(call, result); + callShowRewardedVideoAd(result); break; case "disposeAd": - callDisposeAd(id, call, result); + callDisposeAd(id, result); break; case "isAdLoaded": - callIsAdLoaded(id, call, result); + callIsAdLoaded(id, result); break; default: result.notImplemented(); diff --git a/packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/MobileAd.java b/packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/MobileAd.java index f1456dda26ea..95976faa3f27 100644 --- a/packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/MobileAd.java +++ b/packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/MobileAd.java @@ -11,10 +11,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; -import com.google.android.gms.ads.AdListener; -import com.google.android.gms.ads.AdSize; -import com.google.android.gms.ads.AdView; -import com.google.android.gms.ads.InterstitialAd; +import com.google.android.gms.ads.*; import io.flutter.plugin.common.MethodChannel; import java.util.HashMap; import java.util.Map; diff --git a/packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/RewardedVideoAdWrapper.java b/packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/RewardedVideoAdWrapper.java index cc96880163fb..19781b74c808 100644 --- a/packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/RewardedVideoAdWrapper.java +++ b/packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/RewardedVideoAdWrapper.java @@ -17,10 +17,9 @@ public class RewardedVideoAdWrapper implements RewardedVideoAdListener { private static final String TAG = "flutter"; - final RewardedVideoAd rewardedInstance; - final Activity activity; - final MethodChannel channel; - Status status; + private final RewardedVideoAd rewardedInstance; + private final MethodChannel channel; + private Status status; @Override public void onRewardedVideoAdLoaded() { @@ -76,7 +75,6 @@ enum Status { } public RewardedVideoAdWrapper(Activity activity, MethodChannel channel) { - this.activity = activity; this.channel = channel; this.status = Status.CREATED; this.rewardedInstance = MobileAds.getRewardedVideoAdInstance(activity); diff --git a/packages/firebase_admob/example/android/app/build.gradle b/packages/firebase_admob/example/android/app/build.gradle index f919f535e16d..b3b7fbca28b4 100644 --- a/packages/firebase_admob/example/android/app/build.gradle +++ b/packages/firebase_admob/example/android/app/build.gradle @@ -55,8 +55,8 @@ flutter { dependencies { testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.1.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' + androidTestImplementation 'androidx.test:runner:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' } apply plugin: 'com.google.gms.google-services' diff --git a/packages/firebase_admob/example/android/build.gradle b/packages/firebase_admob/example/android/build.gradle index 695de848ec30..3f271ea72055 100644 --- a/packages/firebase_admob/example/android/build.gradle +++ b/packages/firebase_admob/example/android/build.gradle @@ -6,7 +6,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.3.0' + classpath 'com.android.tools.build:gradle:3.4.2' classpath 'com.google.gms:google-services:4.3.0' } } diff --git a/packages/firebase_admob/example/android/gradle/wrapper/gradle-wrapper.properties b/packages/firebase_admob/example/android/gradle/wrapper/gradle-wrapper.properties index 019065d1d650..4292ae9e47af 100644 --- a/packages/firebase_admob/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/packages/firebase_admob/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Thu Aug 01 22:44:13 BRT 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip diff --git a/packages/firebase_admob/pubspec.yaml b/packages/firebase_admob/pubspec.yaml index 0748194ca909..d741765b358a 100644 --- a/packages/firebase_admob/pubspec.yaml +++ b/packages/firebase_admob/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for Firebase AdMob, supporting banner, interstitial (full-screen), and rewarded video ads author: Flutter Team homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_admob -version: 0.9.0+6 +version: 0.9.0+7 flutter: plugin: