react-native-google-mobile-ads icon indicating copy to clipboard operation
react-native-google-mobile-ads copied to clipboard

[🐛] Redefinition of 'NativeGoogleMobileAdsModuleSpecJSI'

Open relaxxpls opened this issue 1 year ago • 5 comments

What happened?

I tried to compile this library on React Native v0.73.2 using the new architecture on iOS and got the following error

my-folder/ios/build/generated/ios/RNGoogleMobileAdsSpec/RNGoogleMobileAdsSpec.h:46:22 Redefinition of 'NativeGoogleMobileAdsModuleSpecJSI'

react-native-google-mobile-ads version: ^12.10.0

Platforms

iOS, but have not tested behavior on Android

React Native Info

System:
  OS: macOS 14.2.1
  CPU: (10) arm64 Apple M2 Pro
  Memory: 93.23 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.8.0
    path: /private/var/folders/fh/2sm3hq09541_z9dpvh1p11f80000gn/T/xfs-7d215c7b/node
  Yarn:
    version: 4.0.2
    path: /private/var/folders/fh/2sm3hq09541_z9dpvh1p11f80000gn/T/xfs-7d215c7b/yarn
  npm:
    version: 10.1.0
    path: ~/.nvm/versions/node/v20.8.0/bin/npm
  Watchman:
    version: 2023.09.18.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /Users/relaxxpls/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - visionOS 1.0
      - watchOS 10.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11076708
  Xcode:
    version: 15.2/15C500b
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.9
    path: /usr/bin/javac
  Ruby:
    version: 2.7.6
    path: /Users/relaxxpls/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 13.5.1
    wanted: ^13.5.1
  react:
    installed: 18.2.0
    wanted: ^18.2.0
  react-native:
    installed: 0.73.2
    wanted: ^0.73.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: true

Are your using Typescript?

  • [X] My project is using Typescript

package.json

{
  "dependencies": {
    "@dr.pogodin/react-native-fs": "^2.22.0",
    "@dr.pogodin/react-native-static-server": "^0.10.4",
    "@gorhom/bottom-sheet": "^4.6.0",
    "@invertase/react-native-apple-authentication": "^2.3.0",
    "@react-native-community/netinfo": "^11.2.1",
    "@react-native-firebase/analytics": "^18.7.3",
    "@react-native-firebase/app": "^18.7.3",
    "@react-native-firebase/auth": "^18.7.3",
    "@react-native-firebase/messaging": "^18.7.3",
    "@react-native-firebase/remote-config": "^18.7.3",
    "@react-native-google-signin/google-signin": "^11.0.0",
    "@react-navigation/native": "^6.1.9",
    "@react-navigation/stack": "^6.3.20",
    "@sentry/react-native": "^5.17.0",
    "@tanstack/query-sync-storage-persister": "^5.17.19",
    "@tanstack/react-query": "^5.17.19",
    "@tanstack/react-query-persist-client": "^5.17.19",
    "axios": "^1.6.5",
    "color": "^4.2.3",
    "eventemitter3": "^5.0.1",
    "lodash.debounce": "4.0.8",
    "lottie-react-native": "^6.5.1",
    "mixpanel-react-native": "^2.4.0",
    "react": "^18.2.0",
    "react-native": "^0.73.2",
    "react-native-blob-util": "^0.19.6",
    "react-native-code-push": "https://github.com/hamdij0maa/react-native-code-push",
    "react-native-color-matrix-image-filters": "^6.0.7",
    "react-native-config": "^1.5.1",
    "react-native-device-info": "^10.12.0",
    "react-native-fast-image": "^8.6.3",
    "react-native-fbsdk-next": "^12.1.2",
    "react-native-gesture-handler": "^2.14.1",
    "react-native-google-mobile-ads": "^12.10.0",
    "react-native-haptic-feedback": "^2.2.0",
    "react-native-iap": "^12.12.2",
    "react-native-in-app-review": "^4.3.3",
    "react-native-linear-gradient": "^2.8.3",
    "react-native-mmkv": "^2.11.0",
    "react-native-pager-view": "^6.2.3",
    "react-native-reanimated": "^3.6.1",
    "react-native-reanimated-carousel": "^3.5.1",
    "react-native-safe-area-context": "^4.8.2",
    "react-native-screens": "^3.29.0",
    "react-native-share": "^10.0.2",
    "react-native-shimmer-placeholder": "^2.0.9",
    "react-native-sound": "^0.11.2",
    "react-native-sse": "^1.2.0",
    "react-native-svg": "^14.1.0",
    "react-native-tab-view": "^3.5.2",
    "react-native-ui-lib": "^7.15.0",
    "react-native-url-polyfill": "^2.0.0",
    "react-native-vector-icons": "^10.0.3",
    "react-native-video": "^5.2.1",
    "react-native-webview": "^13.6.4",
    "react-native-zip-archive": "^6.1.0",
    "rn-tourguide": "https://github.com/fijit-club/rn-tourguide",
    "sp-react-native-in-app-updates": "^1.3.1",
    "zustand": "^4.5.0"
  },
  "devDependencies": {
    "@babel/core": "7.23.7",
    "@babel/preset-env": "7.23.8",
    "@babel/runtime": "7.23.8",
    "@react-native-community/cli": "^13.5.1",
    "@react-native/babel-preset": "^0.73.19",
    "@react-native/eslint-config": "^0.73.2",
    "@react-native/metro-config": "^0.73.3",
    "@react-native/typescript-config": "^0.73.1",
    "@tanstack/eslint-plugin-query": "^5.17.20",
    "@types/color": "^3.0.6",
    "@types/lodash.debounce": "^4.0.9",
    "@types/react": "18.2.48",
    "@types/react-native-vector-icons": "6.4.18",
    "@types/react-native-video": "5.0.19",
    "@types/react-test-renderer": "18.0.7",
    "@typescript-eslint/eslint-plugin": "6.19.1",
    "@typescript-eslint/parser": "6.19.1",
    "babel-jest": "29.7.0",
    "babel-plugin-transform-remove-console": "6.9.4",
    "eslint": "^8.56.0",
    "eslint-plugin-jest": "27.6.3",
    "jest": "29.7.0",
    "prettier": "3.2.4",
    "react-native-asset": "^2.1.1",
    "react-native-svg-transformer": "^1.3.0",
    "react-test-renderer": "18.2.0",
    "type-fest": "^4.10.1",
    "typescript": "5.3.3"
  },
  "engines": {
    "node": ">=18"
  },
  "packageManager": "[email protected]"
}

app.json

{
  "react-native-google-mobile-ads": {
    "android_app_id": "ca-app-pub-",
    "ios_app_id": "ca-app-pub-",
    "sk_ad_network_items": [
      "cstr6suwn9.skadnetwork",
      "4fzdc2evr5.skadnetwork",
      "4pfyvq9l8r.skadnetwork",
      "2fnua5tdw4.skadnetwork",
      "ydx93a7ass.skadnetwork",
      "5a6flpkh64.skadnetwork",
      "p78axxw29g.skadnetwork",
      "v72qych5uu.skadnetwork",
      "ludvb6z3bs.skadnetwork",
      "cp8zw746q7.skadnetwork",
      "3sh42y64q3.skadnetwork",
      "c6k4g5qg8m.skadnetwork",
      "s39g8k73mm.skadnetwork",
      "3qy4746246.skadnetwork",
      "f38h382jlk.skadnetwork",
      "hs6bdukanm.skadnetwork",
      "v4nxqhlyqp.skadnetwork",
      "wzmmz9fp6w.skadnetwork",
      "yclnxrl5pm.skadnetwork",
      "t38b2kh725.skadnetwork",
      "7ug5zh24hu.skadnetwork",
      "gta9lk7p23.skadnetwork",
      "vutu7akeur.skadnetwork",
      "y5ghdn5j9k.skadnetwork",
      "n6fk4nfna4.skadnetwork",
      "v9wttpbfk9.skadnetwork",
      "n38lu8286q.skadnetwork",
      "47vhws6wlr.skadnetwork",
      "kbd757ywx3.skadnetwork",
      "9t245vhmpl.skadnetwork",
      "eh6m2bh4zr.skadnetwork",
      "a2p9lx4jpn.skadnetwork",
      "22mmun2rn5.skadnetwork",
      "4468km3ulz.skadnetwork",
      "2u9pt9hc89.skadnetwork",
      "8s468mfl3y.skadnetwork",
      "klf5c3l5u5.skadnetwork",
      "ppxm28t8ap.skadnetwork",
      "ecpz2srf59.skadnetwork",
      "uw77j35x4d.skadnetwork",
      "pwa73g5rt2.skadnetwork",
      "mlmmfzh3r3.skadnetwork",
      "578prtvx9j.skadnetwork",
      "4dzt52r2t5.skadnetwork",
      "e5fvkxwrpn.skadnetwork",
      "8c4e2ghe7u.skadnetwork",
      "zq492l623r.skadnetwork",
      "3rd42ekr43.skadnetwork",
      "3qcr597p9d.skadnetwork"
    ],
    "user_tracking_usage_description": ""
  }
}

ios/Podfile

# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
  'require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  )', __dir__]).strip

$RNFirebaseAsStaticFramework = true
$RNGoogleMobileAdsAsStaticFramework = true

platform :ios, min_ios_version_supported
prepare_react_native_project!

# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
# because `react-native-flipper` depends on (FlipperKit,...) that will be excluded
#
# To fix this you can also exclude `react-native-flipper` using a `react-native.config.js`
# 
# module.exports = {
#   dependencies: {
#     ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),
# 
flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled

linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
end

target '' do
  config = use_native_modules!

  pod 'Firebase', :modular_headers => true
  pod 'FirebaseCore', :modular_headers => true
  pod 'GoogleUtilities', :modular_headers => true

  use_frameworks! :linkage => :static

  use_react_native!(
    :path => config[:reactNativePath],
    # Enables Flipper.
    #
    # Note that if you have use_frameworks! enabled, Flipper will not work and
    # you should disable the next line.
    # :flipper_configuration => flipper_config,
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )



  target 'Tests' do
    inherit! :complete
    # Pods for testing
  end

  post_install do |installer|
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', '_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION']
      end
    end

    react_native_post_install(
      installer,
      :mac_catalyst_enabled => false
    )
  end
end

android/build.gradle

No response

android/app/build.gradle

No response

android/settings.gradle

No response

AndroidManifest.xml

No response

relaxxpls avatar Jan 25 '24 16:01 relaxxpls

Hey, thanks for posting this, I had exactly the same issue and never got round to it. React Native v0.73.2 using Expo SDK 50 and v12.10.0 react-native-google-mobile-ads.

I gave up on the new arch for other reasons so didn't investigate further.

tmw102 avatar Jan 25 '24 19:01 tmw102

I am facing the same issue, when trying to run my project using react native new arch

Screenshot 2024-01-29 at 2 46 34 PM

Moussa321 avatar Jan 29 '24 12:01 Moussa321

@dylancom could you help?

relaxxpls avatar Jan 31 '24 15:01 relaxxpls

Hi, I'm just a volunteer adding things to the lib when I need them and sometimes more. It worked at the time but the new arch is probably changing all the time. Would be great if folks currently needing this adding a PR and making it work, I currently don't use the new arch in any project yet.

dylancom avatar Jan 31 '24 15:01 dylancom

Just a quick search I found other packages are also dealing with this. Maybe this helps? https://github.com/facebook/react-native/issues/42670 Please submit a PR if the change fixes your problem, so everyone can benefit :)

dylancom avatar Jan 31 '24 15:01 dylancom

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Feb 28 '24 15:02 github-actions[bot]

I can build successfully with this path:

index 9e48dec..8c25534 100644
--- a/node_modules/react-native-google-mobile-ads/ios/RNGoogleMobileAds/RNGoogleMobileAdsModule.mm
+++ b/node_modules/react-native-google-mobile-ads/ios/RNGoogleMobileAds/RNGoogleMobileAdsModule.mm
@@ -21,9 +21,9 @@
 #import <React/RCTUtils.h>
 
 #import "RNGoogleMobileAdsModule.h"
-#ifdef RCT_NEW_ARCH_ENABLED
-#import "RNGoogleMobileAdsSpec.h"
-#endif
+// #ifdef RCT_NEW_ARCH_ENABLED
+// #import "RNGoogleMobileAdsSpec.h"
+// #endif
 #import "common/RNSharedUtils.h"
 
 @implementation RNGoogleMobileAdsModule

eflashcards avatar Apr 11 '24 14:04 eflashcards

https://github.com/facebook/react-native/commit/46b6453eb6fe5435a792aa4a0f9183446f4fa41f

  • A "react-native" commit has been pushed here for fixing this issue!

eflashcards avatar Apr 11 '24 19:04 eflashcards

@dylancom This is also fixed from React Native commit now and please check my above path. Thank you!

eflashcards avatar Apr 12 '24 03:04 eflashcards