diff --git a/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/FlutterMobileAdsWrapper.java b/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/FlutterMobileAdsWrapper.java index d8d9d65c7..6d90d764a 100644 --- a/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/FlutterMobileAdsWrapper.java +++ b/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/FlutterMobileAdsWrapper.java @@ -18,71 +18,97 @@ import android.os.Build; import android.util.Log; import android.webkit.WebView; + import androidx.annotation.NonNull; + import com.google.android.gms.ads.MobileAds; import com.google.android.gms.ads.OnAdInspectorClosedListener; import com.google.android.gms.ads.RequestConfiguration; import com.google.android.gms.ads.initialization.OnInitializationCompleteListener; + import io.flutter.embedding.engine.FlutterEngine; import io.flutter.plugins.webviewflutter.WebViewFlutterAndroidExternalApi; -/** A wrapper around static methods in {@link com.google.android.gms.ads.MobileAds}. */ +/** + * A wrapper around static methods in {@link com.google.android.gms.ads.MobileAds}. + */ public class FlutterMobileAdsWrapper { - private static final String TAG = "FlutterMobileAdsWrapper"; - - public FlutterMobileAdsWrapper() {} - - /** Initializes the sdk. */ - public void initialize( - @NonNull Context context, @NonNull OnInitializationCompleteListener listener) { - MobileAds.initialize(context, listener); - } - - /** Wrapper for setAppMuted. */ - public void setAppMuted(boolean muted) { - MobileAds.setAppMuted(muted); - } - - /** Wrapper for setAppVolume. */ - public void setAppVolume(double volume) { - MobileAds.setAppVolume((float) volume); - } - - /** Wrapper for disableMediationInitialization. */ - public void disableMediationInitialization(@NonNull Context context) { - MobileAds.disableMediationAdapterInitialization(context); - } - - /** Wrapper for getVersionString. */ - public String getVersionString() { - return MobileAds.getVersion().toString(); - } - - /** Wrapper for getRequestConfiguration. */ - public RequestConfiguration getRequestConfiguration() { - return MobileAds.getRequestConfiguration(); - } - - /** Wrapper for openDebugMenu. */ - public void openDebugMenu(Context context, String adUnitId) { - MobileAds.openDebugMenu(context, adUnitId); - } - - /** Open the ad inspector. */ - public void openAdInspector(Context context, OnAdInspectorClosedListener listener) { - MobileAds.openAdInspector(context, listener); - } - - /** Register the webView for monetization. */ - public void registerWebView(int webViewId, FlutterEngine flutterEngine) { - WebView webView = WebViewFlutterAndroidExternalApi.getWebView(flutterEngine, webViewId); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - Log.w(TAG, "MobileAds.registerWebView does not support API levels less than 21"); - } else if (webView == null) { - Log.w(TAG, "MobileAds.registerWebView unable to find webView with id: " + webViewId); - } else { - MobileAds.registerWebView(webView); + private static final String TAG = "FlutterMobileAdsWrapper"; + + public FlutterMobileAdsWrapper() { + } + + /** + * Initializes the sdk. + */ + public void initialize(@NonNull Context context, @NonNull OnInitializationCompleteListener listener) { + new Thread(() -> { + // Initialize the Google Mobile Ads SDK on a background thread. + MobileAds.initialize(context, listener); + }).start(); + } + + /** + * Wrapper for setAppMuted. + */ + public void setAppMuted(boolean muted) { + MobileAds.setAppMuted(muted); + } + + /** + * Wrapper for setAppVolume. + */ + public void setAppVolume(double volume) { + MobileAds.setAppVolume((float) volume); + } + + /** + * Wrapper for disableMediationInitialization. + */ + public void disableMediationInitialization(@NonNull Context context) { + MobileAds.disableMediationAdapterInitialization(context); + } + + /** + * Wrapper for getVersionString. + */ + public String getVersionString() { + return MobileAds.getVersion().toString(); + } + + /** + * Wrapper for getRequestConfiguration. + */ + public RequestConfiguration getRequestConfiguration() { + return MobileAds.getRequestConfiguration(); + } + + /** + * Wrapper for openDebugMenu. + */ + public void openDebugMenu(Context context, String adUnitId) { + MobileAds.openDebugMenu(context, adUnitId); + } + + /** + * Open the ad inspector. + */ + public void openAdInspector(Context context, OnAdInspectorClosedListener listener) { + MobileAds.openAdInspector(context, listener); + } + + /** + * Register the webView for monetization. + */ + public void registerWebView(int webViewId, FlutterEngine flutterEngine) { + WebView webView = WebViewFlutterAndroidExternalApi.getWebView(flutterEngine, webViewId); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + Log.w(TAG, "MobileAds.registerWebView does not support API levels less than 21"); + } else if (webView == null) { + Log.w(TAG, "MobileAds.registerWebView unable to find webView with id: " + webViewId); + } else { + MobileAds.registerWebView(webView); + } } - } } diff --git a/packages/mediation/gma_mediation_inmobi/example/ios/Flutter/Debug.xcconfig b/packages/mediation/gma_mediation_inmobi/example/ios/Flutter/Debug.xcconfig index 592ceee85..ec97fc6f3 100644 --- a/packages/mediation/gma_mediation_inmobi/example/ios/Flutter/Debug.xcconfig +++ b/packages/mediation/gma_mediation_inmobi/example/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/packages/mediation/gma_mediation_inmobi/example/ios/Flutter/Release.xcconfig b/packages/mediation/gma_mediation_inmobi/example/ios/Flutter/Release.xcconfig index 592ceee85..c4855bfe2 100644 --- a/packages/mediation/gma_mediation_inmobi/example/ios/Flutter/Release.xcconfig +++ b/packages/mediation/gma_mediation_inmobi/example/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/samples/admob/app_open_example/android/app/src/main/AndroidManifest.xml b/samples/admob/app_open_example/android/app/src/main/AndroidManifest.xml index 916e30236..9adc3e7fc 100644 --- a/samples/admob/app_open_example/android/app/src/main/AndroidManifest.xml +++ b/samples/admob/app_open_example/android/app/src/main/AndroidManifest.xml @@ -41,5 +41,8 @@ + \ No newline at end of file diff --git a/samples/admob/app_open_example/ios/Flutter/Debug.xcconfig b/samples/admob/app_open_example/ios/Flutter/Debug.xcconfig index 592ceee85..ec97fc6f3 100644 --- a/samples/admob/app_open_example/ios/Flutter/Debug.xcconfig +++ b/samples/admob/app_open_example/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/samples/admob/app_open_example/ios/Flutter/Release.xcconfig b/samples/admob/app_open_example/ios/Flutter/Release.xcconfig index 592ceee85..c4855bfe2 100644 --- a/samples/admob/app_open_example/ios/Flutter/Release.xcconfig +++ b/samples/admob/app_open_example/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/samples/admob/app_open_example/ios/Podfile b/samples/admob/app_open_example/ios/Podfile new file mode 100644 index 000000000..d97f17e22 --- /dev/null +++ b/samples/admob/app_open_example/ios/Podfile @@ -0,0 +1,44 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '12.0' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_ios_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) + target 'RunnerTests' do + inherit! :search_paths + end +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) + end +end diff --git a/samples/admob/banner_example/android/app/src/main/AndroidManifest.xml b/samples/admob/banner_example/android/app/src/main/AndroidManifest.xml index 7e03252ae..a4dd74815 100644 --- a/samples/admob/banner_example/android/app/src/main/AndroidManifest.xml +++ b/samples/admob/banner_example/android/app/src/main/AndroidManifest.xml @@ -32,5 +32,8 @@ + \ No newline at end of file diff --git a/samples/admob/banner_example/ios/Flutter/Debug.xcconfig b/samples/admob/banner_example/ios/Flutter/Debug.xcconfig index 592ceee85..ec97fc6f3 100644 --- a/samples/admob/banner_example/ios/Flutter/Debug.xcconfig +++ b/samples/admob/banner_example/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/samples/admob/banner_example/ios/Flutter/Release.xcconfig b/samples/admob/banner_example/ios/Flutter/Release.xcconfig index 592ceee85..c4855bfe2 100644 --- a/samples/admob/banner_example/ios/Flutter/Release.xcconfig +++ b/samples/admob/banner_example/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/samples/admob/banner_example/ios/Podfile b/samples/admob/banner_example/ios/Podfile new file mode 100644 index 000000000..d97f17e22 --- /dev/null +++ b/samples/admob/banner_example/ios/Podfile @@ -0,0 +1,44 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '12.0' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_ios_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) + target 'RunnerTests' do + inherit! :search_paths + end +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) + end +end diff --git a/samples/admob/interstitial_example/android/app/src/main/AndroidManifest.xml b/samples/admob/interstitial_example/android/app/src/main/AndroidManifest.xml index b174f62f8..bdee7ea59 100644 --- a/samples/admob/interstitial_example/android/app/src/main/AndroidManifest.xml +++ b/samples/admob/interstitial_example/android/app/src/main/AndroidManifest.xml @@ -27,6 +27,9 @@ + :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_ios_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) + target 'RunnerTests' do + inherit! :search_paths + end +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) + end +end diff --git a/samples/admob/mediation_example/android/app/src/main/AndroidManifest.xml b/samples/admob/mediation_example/android/app/src/main/AndroidManifest.xml index a66526859..c014b0bd9 100644 --- a/samples/admob/mediation_example/android/app/src/main/AndroidManifest.xml +++ b/samples/admob/mediation_example/android/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + diff --git a/samples/admob/native_platform_example/android/app/src/main/AndroidManifest.xml b/samples/admob/native_platform_example/android/app/src/main/AndroidManifest.xml index 6bc8f58f8..f09c0802d 100644 --- a/samples/admob/native_platform_example/android/app/src/main/AndroidManifest.xml +++ b/samples/admob/native_platform_example/android/app/src/main/AndroidManifest.xml @@ -28,6 +28,9 @@ + + + diff --git a/samples/admob/rewarded_example/ios/Flutter/Debug.xcconfig b/samples/admob/rewarded_example/ios/Flutter/Debug.xcconfig index 592ceee85..ec97fc6f3 100644 --- a/samples/admob/rewarded_example/ios/Flutter/Debug.xcconfig +++ b/samples/admob/rewarded_example/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/samples/admob/rewarded_example/ios/Flutter/Release.xcconfig b/samples/admob/rewarded_example/ios/Flutter/Release.xcconfig index 592ceee85..c4855bfe2 100644 --- a/samples/admob/rewarded_example/ios/Flutter/Release.xcconfig +++ b/samples/admob/rewarded_example/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/samples/admob/rewarded_example/ios/Podfile b/samples/admob/rewarded_example/ios/Podfile new file mode 100644 index 000000000..d97f17e22 --- /dev/null +++ b/samples/admob/rewarded_example/ios/Podfile @@ -0,0 +1,44 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '12.0' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_ios_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) + target 'RunnerTests' do + inherit! :search_paths + end +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) + end +end diff --git a/samples/admob/rewarded_interstitial_example/android/app/src/main/AndroidManifest.xml b/samples/admob/rewarded_interstitial_example/android/app/src/main/AndroidManifest.xml index 1a897dc56..c412ab4b5 100644 --- a/samples/admob/rewarded_interstitial_example/android/app/src/main/AndroidManifest.xml +++ b/samples/admob/rewarded_interstitial_example/android/app/src/main/AndroidManifest.xml @@ -32,5 +32,8 @@ + diff --git a/samples/admob/rewarded_interstitial_example/ios/Flutter/Debug.xcconfig b/samples/admob/rewarded_interstitial_example/ios/Flutter/Debug.xcconfig index 592ceee85..ec97fc6f3 100644 --- a/samples/admob/rewarded_interstitial_example/ios/Flutter/Debug.xcconfig +++ b/samples/admob/rewarded_interstitial_example/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/samples/admob/rewarded_interstitial_example/ios/Flutter/Release.xcconfig b/samples/admob/rewarded_interstitial_example/ios/Flutter/Release.xcconfig index 592ceee85..c4855bfe2 100644 --- a/samples/admob/rewarded_interstitial_example/ios/Flutter/Release.xcconfig +++ b/samples/admob/rewarded_interstitial_example/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/samples/admob/rewarded_interstitial_example/ios/Podfile b/samples/admob/rewarded_interstitial_example/ios/Podfile new file mode 100644 index 000000000..d97f17e22 --- /dev/null +++ b/samples/admob/rewarded_interstitial_example/ios/Podfile @@ -0,0 +1,44 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '12.0' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_ios_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) + target 'RunnerTests' do + inherit! :search_paths + end +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) + end +end