From 9c3505a29986b857d29d2c378cf15ad2fc002a93 Mon Sep 17 00:00:00 2001 From: Jason Lian Date: Thu, 15 Feb 2024 16:39:37 +1300 Subject: [PATCH 1/3] 1. on Android, upgrade to support GMA SDK version 22.6.0; on iOS, upgrade to support GMA SDK version 10.10.0, also raised the miminum deployment target to ios 12.4. --- android/build.gradle | 2 +- .../admanager/AdaptiveBannerAdView.java | 9 +- .../com/matejdr/admanager/BannerAdView.java | 146 +++++++++--------- .../admanager/NativeAdViewContainer.java | 9 +- .../admanager/RNAdManagerInterstitial.java | 9 +- package.json | 4 +- react-native-ad-manager.podspec | 6 +- 7 files changed, 96 insertions(+), 89 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index bcb5e2e..d13c2a4 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -60,6 +60,6 @@ repositories { dependencies { //noinspection GradleDynamicVersion implementation "com.facebook.react:react-native:+" // From node_modules - implementation 'com.google.android.gms:play-services-ads:20.5.0' + implementation 'com.google.android.gms:play-services-ads:22.6.0' implementation 'com.google.ads.mediation:facebook:6.8.0.0' } diff --git a/android/src/main/java/com/matejdr/admanager/AdaptiveBannerAdView.java b/android/src/main/java/com/matejdr/admanager/AdaptiveBannerAdView.java index 8d3d03b..3929753 100644 --- a/android/src/main/java/com/matejdr/admanager/AdaptiveBannerAdView.java +++ b/android/src/main/java/com/matejdr/admanager/AdaptiveBannerAdView.java @@ -245,9 +245,12 @@ public void loadBanner() { if (publisherProvidedID != null) { adRequestBuilder.setPublisherProvidedId(publisherProvidedID); } - if (location != null) { - adRequestBuilder.setLocation(location); - } + + // setLocation() became obsolete since GMA SDK version 21.0.0, link reference below: + // https://developers.google.com/admob/android/rel-notes + //if (location != null) { + // adRequestBuilder.setLocation(location); + //} } AdManagerAdRequest adRequest = adRequestBuilder.build(); diff --git a/android/src/main/java/com/matejdr/admanager/BannerAdView.java b/android/src/main/java/com/matejdr/admanager/BannerAdView.java index 4b68471..348a7b6 100644 --- a/android/src/main/java/com/matejdr/admanager/BannerAdView.java +++ b/android/src/main/java/com/matejdr/admanager/BannerAdView.java @@ -31,7 +31,6 @@ import com.facebook.react.modules.core.DeviceEventManagerModule; - class BannerAdView extends ReactViewGroup implements AppEventListener, LifecycleEventListener { protected AdManagerAdView adManagerAdView; ReactApplicationContext currentRNcontext; @@ -63,9 +62,9 @@ public BannerAdView(final Context context, ReactApplicationContext applicationCo currentActivityContext = applicationContext.getCurrentActivity(); applicationContext.addLifecycleEventListener(this); this.createAdView(); - } catch (Exception exception) { + } catch (Exception exception) { this.onException(exception); - } + } } private void onException(Exception exception) { @@ -82,15 +81,15 @@ private void onException(Exception exception) { try { this.adManagerAdView.destroy(); } catch (Exception innerIgnored) { - //ignore it + // ignore it } - this.adManagerAdView = null; + this.adManagerAdView = null; } } catch (Exception e) { // ignore it } - } + } private boolean isFluid() { return AdSize.FLUID.equals(this.adSize); @@ -104,16 +103,17 @@ public void requestLayout() { private void createAdView() { try { - if (this.adManagerAdView != null) this.adManagerAdView.destroy(); - if (this.currentActivityContext == null) return; + if (this.adManagerAdView != null) + this.adManagerAdView.destroy(); + if (this.currentActivityContext == null) + return; this.adManagerAdView = new AdManagerAdView(currentActivityContext); if (isFluid()) { AdManagerAdView.LayoutParams layoutParams = new AdManagerAdView.LayoutParams( - ReactViewGroup.LayoutParams.MATCH_PARENT, - ReactViewGroup.LayoutParams.WRAP_CONTENT - ); + ReactViewGroup.LayoutParams.MATCH_PARENT, + ReactViewGroup.LayoutParams.WRAP_CONTENT); this.adManagerAdView.setLayoutParams(layoutParams); } @@ -205,9 +205,9 @@ public void onAdImpression() { }); this.addView(this.adManagerAdView); } catch (Exception e) { - sendErrorEvent("✅💪Error found at ad manager when createAdView(): "+e.getMessage()+"!"); + sendErrorEvent("✅💪Error found at ad manager when createAdView(): " + e.getMessage() + "!"); this.onException(e); - } + } } // end of createAdView private void sendOnSizeChangeEvent() { @@ -223,20 +223,20 @@ private void sendOnSizeChangeEvent() { event.putDouble("height", height); sendEvent(RNAdManagerBannerViewManager.EVENT_SIZE_CHANGE, event); } catch (Exception e) { - sendErrorEvent("Error found at ad manager when sendOnSizeChangeEvent(): "+e.getMessage()+"!"); - } + sendErrorEvent("Error found at ad manager when sendOnSizeChangeEvent(): " + e.getMessage() + "!"); + } } private void sendEvent(String name, @Nullable WritableMap event) { try { ReactContext reactContext = (ReactContext) getContext(); reactContext.getJSModule(RCTEventEmitter.class).receiveEvent( - getId(), - name, - event); - } catch (Exception e) { - sendErrorEvent("Error found at ad manager when sendEvent(): "+e.getMessage()+"!"); - } + getId(), + name, + event); + } catch (Exception e) { + sendErrorEvent("Error found at ad manager when sendEvent(): " + e.getMessage() + "!"); + } } public void loadBanner() { @@ -271,10 +271,9 @@ public void loadBanner() { } testDevicesList.add(testDevice); } - RequestConfiguration requestConfiguration - = new RequestConfiguration.Builder() - .setTestDeviceIds(testDevicesList) - .build(); + RequestConfiguration requestConfiguration = new RequestConfiguration.Builder() + .setTestDeviceIds(testDevicesList) + .build(); MobileAds.setRequestConfiguration(requestConfiguration); } @@ -286,7 +285,6 @@ public void loadBanner() { adRequestBuilder.addNetworkExtrasBundle(AdMobAdapter.class, bundle); - // Targeting if (hasTargeting) { if (customTargeting != null && customTargeting.length > 0) { @@ -323,34 +321,35 @@ public void loadBanner() { if (publisherProvidedID != null) { adRequestBuilder.setPublisherProvidedId(publisherProvidedID); } - if (location != null) { - adRequestBuilder.setLocation(location); - } + // setLocation() became obsolete since GMA SDK version 21.0.0, link reference + // below: + // https://developers.google.com/admob/android/rel-notes + // if (location != null) { + // adRequestBuilder.setLocation(location); + // } } AdManagerAdRequest adRequest = adRequestBuilder.build(); this.adManagerAdView.loadAd(adRequest); - } catch (Exception e) { - sendErrorEvent("✅💪Error found at ad manager when loadBanner(): "+e.getMessage()+"!"); + } catch (Exception e) { + sendErrorEvent("✅💪Error found at ad manager when loadBanner(): " + e.getMessage() + "!"); this.onException(e); - } - } //End of loadBanner() - + } + } // End of loadBanner() // bubble up error to JS/TS level. public void sendErrorEvent(String errorMessage) { try { WritableMap params = Arguments.createMap(); params.putString("error", errorMessage); - currentRNcontext - .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) - .emit("onError", params); + currentRNcontext + .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) + .emit("onError", params); } catch (Exception e) { - //non-critical error, so ignore. + // non-critical error, so ignore. } - } - + } public void setAdUnitID(String adUnitID) { try { @@ -362,16 +361,16 @@ public void setAdUnitID(String adUnitID) { this.adUnitID = adUnitID; this.adManagerAdView.setAdUnitId(adUnitID); } catch (Exception e) { - sendErrorEvent("Error found at ad manager when setAdUnitID(): "+e.getMessage()+"!"); - } + sendErrorEvent("Error found at ad manager when setAdUnitID(): " + e.getMessage() + "!"); + } } public void setTestDevices(String[] testDevices) { try { this.testDevices = testDevices; } catch (Exception e) { - sendErrorEvent("Error found at ad manager when setTestDevices(): "+e.getMessage()+"!"); - } + sendErrorEvent("Error found at ad manager when setTestDevices(): " + e.getMessage() + "!"); + } } @@ -380,72 +379,72 @@ public void setCustomTargeting(CustomTargeting[] customTargeting) { try { this.customTargeting = customTargeting; } catch (Exception e) { - sendErrorEvent("Error found at ad manager when setCustomTargeting(): "+e.getMessage()+"!"); - } + sendErrorEvent("Error found at ad manager when setCustomTargeting(): " + e.getMessage() + "!"); + } } public void setCategoryExclusions(String[] categoryExclusions) { try { this.categoryExclusions = categoryExclusions; } catch (Exception e) { - sendErrorEvent("Error found at ad manager when setCategoryExclusions(): "+e.getMessage()+"!"); - } + sendErrorEvent("Error found at ad manager when setCategoryExclusions(): " + e.getMessage() + "!"); + } } public void setKeywords(String[] keywords) { try { this.keywords = keywords; } catch (Exception e) { - sendErrorEvent("Error found at ad manager when setKeywords(): "+e.getMessage()+"!"); - } + sendErrorEvent("Error found at ad manager when setKeywords(): " + e.getMessage() + "!"); + } } public void setContentURL(String content_url) { try { this.content_url = content_url; } catch (Exception e) { - sendErrorEvent("Error found at ad manager when setContentURL(): "+e.getMessage()+"!"); - } + sendErrorEvent("Error found at ad manager when setContentURL(): " + e.getMessage() + "!"); + } } public void setPublisherProvidedID(String publisherProvidedID) { try { this.publisherProvidedID = publisherProvidedID; } catch (Exception e) { - sendErrorEvent("Error found at ad manager when setPublisherProvidedID(): "+e.getMessage()+"!"); - } + sendErrorEvent("Error found at ad manager when setPublisherProvidedID(): " + e.getMessage() + "!"); + } } public void setLocation(Location location) { try { this.location = location; } catch (Exception e) { - sendErrorEvent("Error found at ad manager when setLocation(): "+e.getMessage()+"!"); - } + sendErrorEvent("Error found at ad manager when setLocation(): " + e.getMessage() + "!"); + } } public void setAdSize(AdSize adSize) { try { this.adSize = adSize; } catch (Exception e) { - sendErrorEvent("Error found at ad manager when setAdSize(): "+e.getMessage()+"!"); - } + sendErrorEvent("Error found at ad manager when setAdSize(): " + e.getMessage() + "!"); + } } public void setValidAdSizes(AdSize[] adSizes) { try { this.validAdSizes = adSizes; } catch (Exception e) { - sendErrorEvent("Error found at ad manager when setValidAdSizes(): "+e.getMessage()+"!"); - } + sendErrorEvent("Error found at ad manager when setValidAdSizes(): " + e.getMessage() + "!"); + } } public void setCorrelator(String correlator) { try { this.correlator = correlator; } catch (Exception e) { - sendErrorEvent("Error found at ad manager when setCorrelator(): "+e.getMessage()+"!"); - } + sendErrorEvent("Error found at ad manager when setCorrelator(): " + e.getMessage() + "!"); + } } @Override @@ -456,8 +455,8 @@ public void onAppEvent(String name, String info) { event.putString("info", info); sendEvent(RNAdManagerBannerViewManager.EVENT_APP_EVENT, event); } catch (Exception e) { - sendErrorEvent("Error found at ad manager when onAppEvent(): "+e.getMessage()+"!"); - } + sendErrorEvent("Error found at ad manager when onAppEvent(): " + e.getMessage() + "!"); + } } @Override @@ -467,8 +466,8 @@ public void onHostResume() { this.adManagerAdView.resume(); } } catch (Exception e) { - sendErrorEvent("Error found at ad manager when onHostResume(): "+e.getMessage()+"!"); - } + sendErrorEvent("Error found at ad manager when onHostResume(): " + e.getMessage() + "!"); + } } @Override @@ -478,7 +477,7 @@ public void onHostPause() { this.adManagerAdView.pause(); } } catch (Exception e) { - sendErrorEvent("Error found at ad manager when onHostResume(): "+e.getMessage()+"!"); + sendErrorEvent("Error found at ad manager when onHostResume(): " + e.getMessage() + "!"); } } @@ -490,7 +489,7 @@ public void onHostDestroy() { this.adManagerAdView.destroy(); } } catch (Exception e) { - sendErrorEvent("Error found at ad manager when onHostDestroy(): "+e.getMessage()+"!"); + sendErrorEvent("Error found at ad manager when onHostDestroy(): " + e.getMessage() + "!"); } } @@ -500,17 +499,16 @@ public void run() { try { if (isFluid()) { adManagerAdView.measure( - MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY), - MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY) - ); + MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY)); } else { adManagerAdView.measure(width, height); } adManagerAdView.layout(left, top, left + width, top + height); + } catch (Exception e) { + sendErrorEvent( + "Error found at ad manager when MeasureAndLayoutRunnable::run(): " + e.getMessage() + "!"); } - catch (Exception e) { - sendErrorEvent("Error found at ad manager when MeasureAndLayoutRunnable::run(): "+e.getMessage()+"!"); - } } } // end of Runnable } diff --git a/android/src/main/java/com/matejdr/admanager/NativeAdViewContainer.java b/android/src/main/java/com/matejdr/admanager/NativeAdViewContainer.java index 811924e..fc99289 100644 --- a/android/src/main/java/com/matejdr/admanager/NativeAdViewContainer.java +++ b/android/src/main/java/com/matejdr/admanager/NativeAdViewContainer.java @@ -311,9 +311,12 @@ public void run() { if (publisherProvidedID != null) { adRequestBuilder.setPublisherProvidedId(publisherProvidedID); } - if (location != null) { - adRequestBuilder.setLocation(location); - } + + // setLocation() became obsolete since GMA SDK version 21.0.0, link reference below: + // https://developers.google.com/admob/android/rel-notes + //if (location != null) { + // adRequestBuilder.setLocation(location); + //} } AdManagerAdRequest adRequest = adRequestBuilder.build(); diff --git a/android/src/main/java/com/matejdr/admanager/RNAdManagerInterstitial.java b/android/src/main/java/com/matejdr/admanager/RNAdManagerInterstitial.java index b1e18de..ecc6662 100644 --- a/android/src/main/java/com/matejdr/admanager/RNAdManagerInterstitial.java +++ b/android/src/main/java/com/matejdr/admanager/RNAdManagerInterstitial.java @@ -196,9 +196,12 @@ private AdManagerAdRequest buildAdRequest() { if (publisherProvidedID != null) { adRequestBuilder.setPublisherProvidedId(publisherProvidedID); } - if (location != null) { - adRequestBuilder.setLocation(location); - } + + // setLocation() became obsolete since GMA SDK version 21.0.0, link reference below: + // https://developers.google.com/admob/android/rel-notes + //if (location != null) { + // adRequestBuilder.setLocation(location); + //} adRequest = adRequestBuilder.build(); diff --git a/package.json b/package.json index f93cd69..bdad270 100644 --- a/package.json +++ b/package.json @@ -64,8 +64,8 @@ "jest": "^26.0.1", "pod-install": "^0.1.0", "prettier": "^2.0.5", - "react": "16.13.1", - "react-native": "0.64.1", + "react": "17.0.2", + "react-native": "0.67.4", "react-native-builder-bob": "^0.18.0", "release-it": "^14.2.2", "typescript": "^4.1.3" diff --git a/react-native-ad-manager.podspec b/react-native-ad-manager.podspec index 078c8b6..4c0c380 100644 --- a/react-native-ad-manager.podspec +++ b/react-native-ad-manager.podspec @@ -13,13 +13,13 @@ Pod::Spec.new do |s| s.license = package["license"] s.authors = package["author"] - s.platforms = { :ios => "11.0" } + s.platforms = { :ios => "12.4" } s.source = { :git => "https://github.com/NZME/react-native-ad-manager.git", :tag => "v#{s.version}" } s.source_files = "ios/**/*.{h,m,mm}" s.requires_arc = true s.dependency "React-Core" - s.dependency 'Google-Mobile-Ads-SDK', '~> 9.14.0' + s.dependency 'Google-Mobile-Ads-SDK', '~> 10.10.0' s.dependency "GoogleMobileAdsMediationFacebook" -end +end \ No newline at end of file From ae63a393690ec6b0e9b21c78a0de10fb5ed0447e Mon Sep 17 00:00:00 2001 From: Jason Lian Date: Wed, 21 Feb 2024 14:48:01 +1300 Subject: [PATCH 2/3] according to release note, for GMA SDK 22.6.0, it requires compleSdkVersion to be >=33. --- android/build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index d13c2a4..b28f26d 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,7 +1,7 @@ -def DEFAULT_COMPILE_SDK_VERSION = 29 +def DEFAULT_COMPILE_SDK_VERSION = 33 // def DEFAULT_BUILD_TOOLS_VERSION = '29.0.2' -def DEFAULT_MIN_SDK_VERSION = 21 -def DEFAULT_TARGET_SDK_VERSION = 29 +def DEFAULT_MIN_SDK_VERSION = 24 +def DEFAULT_TARGET_SDK_VERSION = 33 buildscript { if (project == rootProject) { From 1618dcf99c0ba30ee855cc7b8303d9eafaf91de4 Mon Sep 17 00:00:00 2001 From: Jason Lian Date: Wed, 21 Feb 2024 16:59:53 +1300 Subject: [PATCH 3/3] because the external GDPR module only supports GMA SDK 22.4.0, so we have to drop GMA SDK version to 22.4.0 as well (from 22.6.0) --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index b28f26d..d562c8b 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -60,6 +60,6 @@ repositories { dependencies { //noinspection GradleDynamicVersion implementation "com.facebook.react:react-native:+" // From node_modules - implementation 'com.google.android.gms:play-services-ads:22.6.0' + implementation 'com.google.android.gms:play-services-ads:22.4.0' implementation 'com.google.ads.mediation:facebook:6.8.0.0' }