ammarahm-ed / react-native-admob-native-ads

A simple and robust library for creating & displaying Admob Native Advanced Ads in your React Native App using Native Views.
https://ammarahm-ed.github.io/react-native-admob-native-ads/docs/introduction/
MIT License
383 stars 130 forks source link

[M1 Silicon][0.6.0] Build workaround with react-native-google-mobile-ads[8.2.3] #324

Open AuroPick opened 1 year ago

AuroPick commented 1 year ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-admob-native-ads@0.6.0 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-admob-native-ads/ios/RNAdMobManager/RNAdMobUnifiedAdQueueWrapper.m b/node_modules/react-native-admob-native-ads/ios/RNAdMobManager/RNAdMobUnifiedAdQueueWrapper.m
index 2f4724a..a636e31 100644
--- a/node_modules/react-native-admob-native-ads/ios/RNAdMobManager/RNAdMobUnifiedAdQueueWrapper.m
+++ b/node_modules/react-native-admob-native-ads/ios/RNAdMobManager/RNAdMobUnifiedAdQueueWrapper.m
@@ -13,7 +13,7 @@
 #import "CacheManager.h"
 @import GoogleMobileAds;
 #ifdef MEDIATION_FACEBOOK
-@import FacebookAdapter;
+@import MetaAdapter;
 #endif

 @implementation RNAdMobUnifiedAdQueueWrapper{
diff --git a/node_modules/react-native-admob-native-ads/ios/RNAdMobManager/RNGADNativeView.m b/node_modules/react-native-admob-native-ads/ios/RNAdMobManager/RNGADNativeView.m
index c876c8b..f4a82eb 100755
--- a/node_modules/react-native-admob-native-ads/ios/RNAdMobManager/RNGADNativeView.m
+++ b/node_modules/react-native-admob-native-ads/ios/RNAdMobManager/RNGADNativeView.m
@@ -8,7 +8,7 @@
 #import <React/RCTUIManagerUtils.h>

 #ifdef MEDIATION_FACEBOOK
-@import FacebookAdapter;
+@import MetaAdapter;
 #endif

 @implementation RNGADNativeView : GADNativeAdView
diff --git a/node_modules/react-native-admob-native-ads/ios/RNAdMobManager/RNNativeAdMobUtils.h b/node_modules/react-native-admob-native-ads/ios/RNAdMobManager/RNNativeAdMobUtils.h
index 4da2264..2d51e22 100755
--- a/node_modules/react-native-admob-native-ads/ios/RNAdMobManager/RNNativeAdMobUtils.h
+++ b/node_modules/react-native-admob-native-ads/ios/RNAdMobManager/RNNativeAdMobUtils.h
@@ -1,6 +1,6 @@
 #import <Foundation/Foundation.h>

-#if __has_include(<FacebookAdapter/FacebookAdapter.h>)
+#if __has_include(<MetaAdapter/MetaAdapter.h>)
 #define MEDIATION_FACEBOOK
 #endif

diff --git a/node_modules/react-native-admob-native-ads/react-native-admob-native-ads.podspec b/node_modules/react-native-admob-native-ads/react-native-admob-native-ads.podspec
index 7b92e8e..dad4d34 100755
--- a/node_modules/react-native-admob-native-ads/react-native-admob-native-ads.podspec
+++ b/node_modules/react-native-admob-native-ads/react-native-admob-native-ads.podspec
@@ -19,7 +19,7 @@ Pod::Spec.new do |s|
   # So instead we add the default location of the framework to the framework
   # search paths, and we rely on consumers of this library to add
   # Google-Mobile-Ads-SDK as a direct dependency.
-  s.weak_frameworks        = 'GoogleMobileAds', 'FacebookAdapter'
+  s.weak_frameworks        = 'GoogleMobileAds', 'MetaAdapter'
   s.pod_target_xcconfig    = {
     'FRAMEWORK_SEARCH_PATHS' => '"$(PODS_ROOT)/Google-Mobile-Ads-SDK/Frameworks/**" '\
                                 '"$(PODS_ROOT)/FBAudienceNetwork/**" '\

This issue body was partially generated by patch-package.

and also I used pod-patch to create custom FBAudienceNetwork podspec to build in M1 environment

here is custom podspec and diff file I used:

{
  "name": "FBAudienceNetwork",
  "version": "6.12.0",
  "summary": "Facebook Audience Network Mobile App Ad SDK",
  "description": "Facebook's Audience Network allows you to monetize your iOS and Android apps with Facebook ads.",
  "homepage": "https://developers.facebook.com/docs/audience-network",
  "license": {
    "type": "Copyright",
    "text": "              Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved.\n\n              You are hereby granted a non-exclusive, worldwide, royalty-free license to use,\n              copy, modify, and distribute this software in source code or binary form for use\n              in connection with the web services and APIs provided by Facebook.\n\n              As with any software that integrates with the Facebook platform, your use of\n              this software is subject to the Facebook Platform Policy\n              [http://developers.facebook.com/policy/]. This copyright notice shall be\n              included in all copies or substantial portions of the software.\n\n              THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n              IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n              FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n              COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n              IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n              CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  "authors": "Facebook",
  "platforms": {
    "ios": "10.0"
  },
  "source": {
    "http": "https://developers.facebook.com/resources/FBAudienceNetwork-6.12.0.zip",
    "sha1": "9d06f49050020e623b948089713ff55e2ba40c7d"
  },
  "source_files": "Static/FBAudienceNetwork.xcframework/**/*.h",
  "public_header_files": "Static/FBAudienceNetwork.xcframework/**/*.h",
  "frameworks": [
    "AudioToolbox",
    "StoreKit",
    "CoreGraphics",
    "UIKit",
    "Foundation",
    "Security",
    "CoreImage",
    "AVFoundation",
    "CoreMedia"
  ],
  "weak_frameworks": [
    "AdSupport",
    "CFNetwork",
    "CoreMotion",
    "CoreTelephony",
    "LocalAuthentication",
    "SafariServices",
    "SystemConfiguration",
    "VideoToolbox",
    "WebKit"
  ],
  "libraries": [
    "c++",
    "xml2",
    "z"
  ],
  "user_target_xcconfig": {
    "EXCLUDED_ARCHS[sdk=iphonesimulator*]": "arm64"
  },
  "pod_target_xcconfig": {
    "EXCLUDED_ARCHS[sdk=iphonesimulator*]": "arm64"
  },
  "vendored_frameworks": "Static/FBAudienceNetwork.xcframework",
  "requires_arc": true,
  "swift_versions": "5.0",
  "swift_version": "5.0"
}
--- FBAudienceNetwork.podspec.json  2023-01-11 23:15:22
+++ FBAudienceNetwork_new.podspec.json  2023-01-11 23:12:04
@@ -46,13 +46,13 @@
     "z"
   ],
   "user_target_xcconfig": {
-    "EXCLUDED_ARCHS[sdk=iphonesimulator*]": "i386"
+    "EXCLUDED_ARCHS[sdk=iphonesimulator*]": "arm64"
   },
   "pod_target_xcconfig": {
-    "EXCLUDED_ARCHS[sdk=iphonesimulator*]": "i386"
+    "EXCLUDED_ARCHS[sdk=iphonesimulator*]": "arm64"
   },
   "vendored_frameworks": "Static/FBAudienceNetwork.xcframework",
   "requires_arc": true,
   "swift_versions": "5.0",
   "swift_version": "5.0"
-}
+}
\ No newline at end of file
Screenshot 2023-01-12 at 16 06 00

here is my podfile:

target 'Project' do

  # ...

  # #region react-native-admob-native-ads pod dependencies
  pod 'FBAudienceNetwork', :podspec => './pod-patch/.patched/FBAudienceNetwork/6.12.0/FBAudienceNetwork.podspec.json'

  pod 'Google-Mobile-Ads-SDK', '9.12.0'
  pod 'GoogleMobileAdsMediationFacebook', '6.12.0.0'
  # #endregion

  # ...

after applying these changes simply run

cd ios && pod deintegrate && rm -rf Podfile.lock && cd ..

cd ios && pod install --repo-update && cd ..
retireearly commented 1 year ago

what react-native-google-mobile-ads version did you use? Also can you provide little more detail on how pod-patch was created?

AuroPick commented 1 year ago

what react-native-google-mobile-ads version did you use? Also can you provide little more detail on how pod-patch was created?

8.2.3

AuroPick commented 1 year ago

check pod-patch documentation

retireearly commented 1 year ago

Thanks for the help. I have more issue.

When I call AdManager.isTestDevice, I am getting RNAdmobNativeAdsManager.isTestDevice was called with 0 arguments but expects 1 arguments. How did you resolve this?

ihdev524 commented 1 year ago

Command PhaseScriptExecution failed with a nonzero exit code

getting this

AuroPick commented 1 year ago

Thanks for the help. I have more issue.

When I call AdManager.isTestDevice, I am getting RNAdmobNativeAdsManager.isTestDevice was called with 0 arguments but expects 1 arguments. How did you resolve this?

actually i did not use isTestDevice anywhere in my code but when I look to source code it looks like isTestDevice wants an argument but does not provided in js side. I am not the library owner so i do not have any idea

https://github.com/ammarahm-ed/react-native-admob-native-ads/blob/3948fcc6a005d1e7bc0167819d8c10d4a179822d/src/AdManager.js#L11

https://github.com/ammarahm-ed/react-native-admob-native-ads/blob/3948fcc6a005d1e7bc0167819d8c10d4a179822d/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNAdmobNativeAdsManager.java#L88

AuroPick commented 1 year ago

Command PhaseScriptExecution failed with a nonzero exit code

getting this

I have no idea but it can be an issue with the pods

absolutezero13 commented 1 year ago

@AuroPick any solution for android? It crashes for the same reason

ammarahm-ed commented 1 year ago

@absolutezero13 Try v0.6.3. It builds correctly on both android & ios.