invertase / react-native-google-mobile-ads

React Native Google Mobile Ads enables you to monetize your app with AdMob.
https://docs.page/invertase/react-native-google-mobile-ads
Other
674 stars 135 forks source link

[🐛] ios_app_id key not found in react-native-google-mobile-ads key in app.json. App will crash without it. #273

Closed livnunes closed 1 year ago

livnunes commented 1 year ago

What happened?

Hello, I'm currently having this issue with react-native-google-mobile-ads. I'm unable to build the project because the same error always pops up. I've checked the app.json and the ios_app_id is there. Has anyone had this issue before? I'm also using the latest version 8.2.1 of the package. Please let me know if I need to add more info into this issue. Thanks in advance!

Platforms

Only on iOS

React Native Info

System:
    OS: macOS 12.6
    CPU: (8) x64 Apple M1
    Memory: 58.94 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: Not Found
    npm: 8.12.1 - /usr/local/bin/npm
    Watchman: Not Found
  Managers:
    CocoaPods: 1.11.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1
    Android SDK: Not Found
  IDEs:
    Android Studio: 2021.2 AI-212.5712.43.2112.8512546
    Xcode: 14.1/14B47b - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.12 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2 
    react-native: 0.68.1 => 0.68.1 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Are your using Typescript?

package.json

{
  "name": "TestPlayer",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@delightfulstudio/react-native-wheel-picker-android": "^2.1.3",
    "@dudigital/react-native-zoomable-view": "^1.0.13",
    "@invertase/react-native-apple-authentication": "^1.1.2",
    "@notifee/react-native": "^7.1.0",
    "@ptomasroos/react-native-multi-slider": "^2.2.2",
    "@react-native-community/art": "^1.2.0",
    "@react-native-community/async-storage": "^1.6.1",
    "@react-native-community/slider": "^4.2.2",
    "@react-native-firebase/analytics": "^16.4.4",
    "@react-native-firebase/app": "^16.4.4",
    "@react-native-firebase/crashlytics": "^16.4.4",
    "@react-native-firebase/messaging": "^16.4.4",
    "@react-navigation/drawer": "^6.4.1",
    "@react-navigation/material-top-tabs": "^6.2.1",
    "@react-navigation/native": "^6.0.10",
    "@react-navigation/native-stack": "^6.6.2",
    "art": "^0.10.3",
    "axios": "^0.18.0",
    "buffer": "^5.2.1",
    "d3": "^5.7.0",
    "d3-shape": "^1.2.2",
    "events": "^3.0.0",
    "jwt-decode": "^2.2.0",
    "react": "17.0.2",
    "react-native": "0.68.1",
    "react-native-add-shortcuts": "^1.0.1",
    "react-native-animatable": "^1.3.0",
    "react-native-autolink": "^1.8.1",
    "react-native-blob-util": "^0.16.0",
    "react-native-calendars": "^1.1283.0",
    "react-native-camera": "^3.6.0",
    "react-native-chart-kit": "^6.11.0",
    "react-native-date-picker": "^4.2.2",
    "react-native-device-info": "^5.5.4",
    "react-native-emoji-selector": "^0.2.0",
    "react-native-fbsdk-next": "^11.1.0",
    "react-native-fingerprint-scanner": "^4.0.0",
    "react-native-geolocation-service": "^5.3.0-beta.4",
    "react-native-gesture-handler": "^2.4.2",
    "react-native-google-mobile-ads": "^8.2.1",
    "react-native-image-crop-picker": "^0.20.3",
    "react-native-image-helper": "0.0.2",
    "react-native-image-pan-zoom": "^2.1.11",
    "react-native-image-zoom-viewer": "^2.2.27",
    "react-native-keyboard-aware-scroll-view": "^0.9.5",
    "react-native-linear-gradient": "^2.5.4",
    "react-native-localization": "^1.0.10",
    "react-native-maps": "^0.21.0",
    "react-native-nodemediaclient": "^0.1.5",
    "react-native-orientation-locker": "^1.3.1",
    "react-native-otp-verify": "^1.0.3",
    "react-native-pager-view": "^5.4.24",
    "react-native-pdf": "^6.5.0",
    "react-native-progress": "^5.0.0",
    "react-native-qrcode-svg": "^5.2.0",
    "react-native-reanimated": "^2.8.0",
    "react-native-safe-area-context": "^4.2.5",
    "react-native-screens": "^3.13.1",
    "react-native-simple-gauge": "^0.3.1",
    "react-native-snap-slider": "^0.3.0",
    "react-native-stripe-payments": "^1.0.6",
    "react-native-svg": "^9.11.1",
    "react-native-tab-view": "^3.1.1",
    "react-native-thumbnail-video": "^0.1.2",
    "react-native-vector-icons": "^4.6.0",
    "react-native-video": "^4.4.4",
    "react-native-webview": "^9.1.4",
    "react-redux": "^5.1.0",
    "stream": "0.0.2",
    "throttle-debounce": "^2.1.0",
    "timers": "^0.1.1",
    "whatwg-fetch-timeout": "^2.0.2-timeout",
    "whatwg-url": "^8.4.0",
    "xml2js": "^0.4.19"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "babel-jest": "^26.6.3",
    "babel-plugin-transform-remove-console": "^6.9.4",
    "eslint": "7.32.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "^0.67.0",
    "react-test-renderer": "17.0.2"
  },
  "jest": {
    "preset": "react-native"
  }
}

app.json

{
  "name": "TestPlayer",
  "displayName": "TestPlayer",
  "react-native-google-mobile-ads": {
    "android_app_id": "ca-app-pub-0000000~00000000",
    "ios_app_id": "ca-app-pub-0000000~00000000",
    "delay_app_measurement_init": true,
    "user_tracking_usage_description": "This identifier will be used to deliver personalized ads to you."
  }
}

ios/Podfile

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '12.0'
install! 'cocoapods', :deterministic_uuids => false

use_frameworks! :linkage => :static

target 'TestPlayer' do
  config = use_native_modules!

  # Flags change depending on the env values.
  flags = get_default_flags()
  $RNGoogleMobileAdsAsStaticFramework = true
  $RNFirebaseAnalyticsWithoutAdIdSupport = true

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => flags[:hermes_enabled],
    :fabric_enabled => flags[:fabric_enabled],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

end

android/build.gradle

No response

android/app/build.gradle

No response

android/settings.gradle

No response

AndroidManifest.xml

No response

mikehardy commented 1 year ago

Have you run pod install? The app.json is processed during the pod install phase, where the keys are read and stuffed into the Info.plist where they are available to the app.

Others have had this problem but it is typically Expo people that put the app.json keys in the wrong spot (under the expo JSON key, not at the top level). Your app.json looks fine so I am guessing it is something

Or perhaps it cannot find the app.json for some reason. If you look at the build log it will detail where it looked for the app.json and then all the processing steps.

The script is here so you can instrument it if you need to: https://github.com/invertase/react-native-google-mobile-ads/blob/main/ios_config.sh

livnunes commented 1 year ago

Have you run pod install? The app.json is processed during the pod install phase, where the keys are read and stuffed into the Info.plist where they are available to the app.

Others have had this problem but it is typically Expo people that put the app.json keys in the wrong spot (under the expo JSON key, not at the top level). Your app.json looks fine so I am guessing it is something

Or perhaps it cannot find the app.json for some reason. If you look at the build log it will detail where it looked for the app.json and then all the processing steps.

The script is here so you can instrument it if you need to: https://github.com/invertase/react-native-google-mobile-ads/blob/main/ios_config.sh

@mikehardy I ran pod install everytime, here is a log of the build, I think I've found the issue... could these Ruby errors be related to this?

info: -> RNGoogleMobileAds build script started info: 1) Locating app.json file: info: (1 of 2) Searching in '/Users/user217708/Documents/Projetos/TestPlayer' for a app.json file. info: app.json found at /Users/user217708/Documents/Projetos/TestPlayer/app.json /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require': dlopen(/Library/Ruby/Gems/2.6.0/gems/strscan-3.0.3/lib/strscan.bundle, 0x0009): tried: '/Library/Ruby/Gems/2.6.0/gems/strscan-3.0.3/lib/strscan.bundle' (mach-o file, but is an incompatible architecture (have (arm64), need (x86_64))) - /Library/Ruby/Gems/2.6.0/gems/strscan-3.0.3/lib/strscan.bundle (LoadError) from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:inrequire' from /Library/Ruby/Gems/2.6.0/gems/json-2.6.2/lib/json/pure/parser.rb:2:in <top (required)>' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:inrequire' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require' from /Library/Ruby/Gems/2.6.0/gems/json-2.6.2/lib/json/pure.rb:7:in' from /Library/Ruby/Gems/2.6.0/gems/json-2.6.2/lib/json/pure.rb:6:in <module:JSON>' from /Library/Ruby/Gems/2.6.0/gems/json-2.6.2/lib/json/pure.rb:3:in<top (required)>' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:inrequire' from /Library/Ruby/Gems/2.6.0/gems/json-2.6.2/lib/json.rb:581:in rescue in <module:JSON>' from /Library/Ruby/Gems/2.6.0/gems/json-2.6.2/lib/json.rb:578:in' from /Library/Ruby/Gems/2.6.0/gems/json-2.6.2/lib/json.rb:575:in <top (required)>' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:inrequire' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require' from -e:1:in

' /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require': dlopen(/Library/Ruby/Gems/2.6.0/gems/json-2.6.2/lib/json/ext/parser.bundle, 0x0009): tried: '/Library/Ruby/Gems/2.6.0/gems/json-2.6.2/lib/json/ext/parser.bundle' (mach-o file, but is an incompatible architecture (have (arm64), need (x86_64))) - /Library/Ruby/Gems/2.6.0/gems/json-2.6.2/lib/json/ext/parser.bundle (LoadError) from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:inrequire' from /Library/Ruby/Gems/2.6.0/gems/json-2.6.2/lib/json/ext.rb:7:in <module:Ext>' from /Library/Ruby/Gems/2.6.0/gems/json-2.6.2/lib/json/ext.rb:6:in' from /Library/Ruby/Gems/2.6.0/gems/json-2.6.2/lib/json/ext.rb:3:in <top (required)>' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:inrequire' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require' from /Library/Ruby/Gems/2.6.0/gems/json-2.6.2/lib/json.rb:579:in' from /Library/Ruby/Gems/2.6.0/gems/json-2.6.2/lib/json.rb:575:in <top (required)>' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:inrequire' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require' from -e:1:in
' info: 2) Injecting Info.plist entries: -> 0) google_mobile_ads_json_raw string e30= error: ios_app_id key not found in react-native-google-mobile-ads key in app.json. App will crash without it.

mikehardy commented 1 year ago

Almost definitely, I don't believe cocoapods works well on 2.6.0? I expect ruby 2-current-stable or 3-current-stable in the scripts

react-native currently prefers 2.7.6 so I'd use that https://github.com/facebook/react-native/blob/main/template/_ruby-version

The built-in macOS ruby is not supported (they never update it...) and I personally use rvm to manage my ruby version https://reactnative.dev/docs/environment-setup#ruby

livnunes commented 1 year ago

Almost definitely, I don't believe cocoapods works well on 2.6.0? I expect ruby 2-current-stable or 3-current-stable in the scripts

react-native currently prefers 2.7.6 so I'd use that https://github.com/facebook/react-native/blob/main/template/_ruby-version

The built-in macOS ruby is not supported (they never update it...) and I personally use rvm to manage my ruby version https://reactnative.dev/docs/environment-setup#ruby

Thank you so much for your help, will get it updated and try again!

luisfusim commented 1 year ago

Hello everyone, thanks in advance for your help/answer ... I'm not using EXPO, but I need to get the ios_app_id from a ENV file ... I tried with a app.config.js, but I continue getting the error that ios_app_id key not found in react-native-google-mobile-ads key in app.json. App will crash without it.

Is an option to avoid ios_app_id in app.json and putting it on some other file?