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
625 stars 121 forks source link

[🐛] ios_app_id key not found in react-native-google-mobile-ads key in app.json #547

Closed renatomserra closed 2 months ago

renatomserra commented 4 months ago

What happened?

When running npm run ios getting the following:

info: -> RNGoogleMobileAds build script started
info: 1) Locating app.json file:
info:      (1 of 2) Searching in '/Users/renatoserra/projects/DogCatApp' for a app.json/app.config.js file.
info:      app.json found at /Users/renatoserra/projects/DogCatApp/web-build/app.json
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.

Im on an ejected Expo. I feel like i followed the instructions correctly and ive tried all the suggestions in closed issues i could find. I might be missing something obvious after looking so much :D Tried downgrading a few versions still getting the same. Happy to provide more info or try anything that helps me find the issue.

Thank you!

Platforms

Android and iOS

React Native Info

System:
    OS: macOS 12.5
    CPU: (8) x64 Apple M1 Pro
    Memory: 79.64 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.5.0 - ~/.nvm/versions/node/v16.5.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 10.2.4 - /opt/homebrew/bin/npm
    Watchman: 2023.12.04.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.12.1 - /Users/renatoserra/.rbenv/shims/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1
    Android SDK: Not Found
  IDEs:
    Android Studio: 2021.2 AI-212.5712.43.2112.8815526
    Xcode: 14.2/14C18 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.16.1 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: 8.0.4 => 8.0.4
    react: 18.0.0 => 18.0.0
    react-native: 0.69.9 => 0.69.9
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Are your using Typescript?

package.json

{
  "scripts": {
    "start": "react-native start",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "web": "expo start --web",
    "eject": "expo eject",
    "test": "jest",
    "translate": "node ./scripts/translate.js",
    "new_ios_version": "node ./scripts/new_ios_version.js",
    "postinstall": "patch-package",
    "androidProd": "npx react-native run-android --variant=release",
    "bump-patch": "npm version patch --no-git-tag-version && bundle exec fastlane bump",
    "bump-minor": "npm version minor --no-git-tag-version && bundle exec fastlane bump",
    "bump-major": "npm version major --no-git-tag-version && bundle exec fastlane bump"
  },
  "dependencies": {
    "@eva-design/eva": "2.2.0",
    "@invertase/react-native-apple-authentication": "2.1.5",
    "@react-native-async-storage/async-storage": "1.17.7",
    "@react-native-community/cli": "8.0.4",
    "@react-native-community/cli-platform-android": "8.0.4",
    "@react-native-community/datetimepicker": "6.2.0",
    "@react-native-community/netinfo": "^9.4.1",
    "@react-native-firebase/analytics": "17.5.0",
    "@react-native-firebase/app": "17.5.0",
    "@react-native-firebase/crashlytics": "17.5.0",
    "@react-native-firebase/dynamic-links": "17.5.0",
    "@react-native-firebase/perf": "17.5.0",
    "@react-native-masked-view/masked-view": "0.2.7",
    "@react-native-picker/picker": "2.4.8",
    "@react-navigation/bottom-tabs": "6.5.8",
    "@react-navigation/core": "6.4.9",
    "@react-navigation/drawer": "6.6.3",
    "@react-navigation/elements": "1.3.18",
    "@react-navigation/material-top-tabs": "6.6.3",
    "@react-navigation/native": "6.1.7",
    "@react-navigation/stack": "6.3.17",
    "@sentry/react-native": "5.5.0",
    "@shopify/flash-list": "1.5.0",
    "@ui-kitten/components": "5.1.2",
    "@ui-kitten/eva-icons": "5.1.2",
    "@ui-kitten/metro-config": "5.1.2",
    "all": "^0.0.0",
    "axios": "0.26.1",
    "eslint": "8.36.0",
    "eslint-plugin-react-hooks": "4.6.0",
    "expo": "46.0.15",
    "expo-asset": "8.5.0",
    "expo-auth-session": "3.7.1",
    "expo-image-manipulator": "10.3.1",
    "expo-linking": "3.1.0",
    "expo-media-library": "14.1.0",
    "expo-modules-core": "0.11.10",
    "expo-notifications": "0.16.1",
    "expo-random": "12.3.0",
    "expo-screen-capture": "4.3.0",
    "expo-store-review": "5.2.0",
    "fuse.js": "6.5.2",
    "i18next": "^23.7.9",
    "iso-country-currency": "0.6.0",
    "jsonwebtoken": "^9.0.2",
    "lodash": "4.17.21",
    "lottie-ios": "3.4.0",
    "lottie-react-native": "5.1.6",
    "make-plural": "^7.3.0",
    "metro-react-native-babel-preset": "0.70.3",
    "mixpanel-react-native": "2.3.1",
    "moment": "2.29.4",
    "moment-timezone": "^0.5.43",
    "openai": "^4.24.1",
    "patch-package": "6.4.7",
    "react": "18.0.0",
    "react-dom": "18.0.0",
    "react-freeze": "1.0.3",
    "react-i18next": "^13.5.0",
    "react-native": "0.69.9",
    "react-native-actions-sheet": "0.8.29",
    "react-native-actions-shortcuts": "^1.0.1",
    "react-native-autocomplete-dropdown": "2.1.1",
    "react-native-calendars": "^1.1301.0",
    "react-native-chart-kit": "6.12.0",
    "react-native-check-app-install": "0.0.5",
    "react-native-device-info": "8.3.1",
    "react-native-document-picker": "8.1.0",
    "react-native-dotenv": "3.3.1",
    "react-native-fast-image": "8.5.11",
    "react-native-fbsdk-next": "10.1.0",
    "react-native-file-viewer": "2.1.5",
    "react-native-format-currency": "0.0.1",
    "react-native-fs": "2.20.0",
    "react-native-gesture-handler": "2.9.0",
    "react-native-google-mobile-ads": "^12.10.0",
    "react-native-haptic-feedback": "2.0.3",
    "react-native-iap": "12.10.8",
    "react-native-image-picker": "5.4.0",
    "react-native-iphone-x-helper": "1.3.1",
    "react-native-keyboard-aware-scroll-view": "0.9.5",
    "react-native-localize": "^3.0.2",
    "react-native-modal": "13.0.1",
    "react-native-modal-datetime-picker": "13.0.0",
    "react-native-offline": "^6.0.2",
    "react-native-open-maps": "0.4.0",
    "react-native-pager-view": "5.4.24",
    "react-native-permissions": "3.2.0",
    "react-native-picker-select": "8.0.4",
    "react-native-popup-menu": "0.16.1",
    "react-native-reanimated": "3.4.2",
    "react-native-reanimated-carousel": "3.5.1",
    "react-native-safe-area-context": "4.4.1",
    "react-native-screens": "3.24.0",
    "react-native-share": "7.3.6",
    "react-native-splash-screen": "3.3.0",
    "react-native-svg": "12.3.0",
    "react-native-svg-transformer": "1.0.0",
    "react-native-tab-view": "3.1.1",
    "react-native-toast-message": "2.1.6",
    "react-native-ux-cam": "5.4.13",
    "react-native-vector-icons": "9.2.0",
    "react-native-view-shot": "3.3.0",
    "react-native-wagmi-charts": "2.3.0",
    "react-native-webview": "13.5.1",
    "react-redux": "7.2.6",
    "react-test-renderer": "18.0.0",
    "recyclerlistview": "4.2.0",
    "redux": "4.1.2",
    "redux-thunk": "2.3.0",
    "use-latest-callback": "0.1.6",
    "use-sync-external-store": "1.2.0",
    "uuid": "3.4.0"
  },
  "devDependencies": {
    "@babel/core": "7.12.9",
    "@babel/plugin-proposal-private-methods": "7.18.6",
    "babel-jest": "27.5.1",
    "babel-preset-expo": "9.1.0",
    "eslint-plugin-react": "7.32.2",
    "eslint-plugin-react-native": "4.0.0",
    "jest": "26.6.3"
  },
  "private": true,
  "name": "Placeholder",
  "version": "1.18.74"
}

app.json

{
  "expo": {
    "name": "placeholder",
    "slug": "placeholder",
    "privacy": "unlisted",
    "userInterfaceStyle": "automatic",
    "scheme": "placeholder",
    ...
  },
  "react-native-google-mobile-ads": {
    "android_app_id": "ca-app-pub-.....",
    "ios_app_id": "ca-app-pub-......",
    "user_tracking_usage_description": "This identifier will be used to deliver personalized ads to you.",
    "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"
    ]
  }
}

ios/Podfile

# frozen_string_literal: true

require File.join(File.dirname(`node --print "require.resolve('expo/package.json')"`), 'scripts/autolinking')
require File.join(File.dirname(`node --print "require.resolve('react-native/package.json')"`), 'scripts/react_native_pods')
require File.join(File.dirname(`node --print "require.resolve('@react-native-community/cli-platform-ios/package.json')"`), 'native_modules')

$ExpoUseSources = ['expo-camera', 'expo-notifications', '@unimodules/code']
$RNFirebaseAsStaticFramework = true

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

production = ENV["PRODUCTION"] == "1"

require 'json'
podfile_properties = begin
                       JSON.parse(File.read('./Podfile.properties.json'))
                     rescue StandardError
                       {}
                     end

target 'DogCatApp' do
  use_expo_modules!

  pre_install do |installer|
    Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}

    installer.pod_targets.each do |pod|
      if pod.name.eql?('RNPermissions') || pod.name.start_with?('Permission-')
        def pod.build_type;
          Pod::BuildType.static_library
        end
      end
    end
  end

  post_integrate do |installer|
    begin
      expo_patch_react_imports!(installer)
    rescue => e
      Pod::UI.warn e
    end
    begin
      expo_patch_react_imports!(installer)
    rescue => e
      Pod::UI.warn e
    end
    begin
      expo_patch_react_imports!(installer)
    rescue => e
      Pod::UI.warn e
    end
    begin
      expo_patch_react_imports!(installer)
    rescue => e
      Pod::UI.warn e
    end
    begin
      expo_patch_react_imports!(installer)
    rescue => e
      Pod::UI.warn e
    end
    begin
      expo_patch_react_imports!(installer)
    rescue => e
      Pod::UI.warn e
    end
  end
  $RNFirebaseAsStaticFramework = true
  config = use_native_modules!
  use_frameworks! linkage: :static

  # Flags change depending on the env values.
  flags = get_default_flags()

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :production => production,
    :hermes_enabled => flags[:hermes_enabled],
    :fabric_enabled => false,
    #:flipper_configuration => FlipperConfiguration.enabled,
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )
  # Uncomment the code below to enable Flipper.
  #
  # You should not install Flipper in CI environments when creating release
  # builds, this will lead to significantly slower build times.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work.
  #
  #  use_flipper!
  use_frameworks! linkage: :static

  $RNGoogleMobileAdsAsStaticFramework = true

  pod 'react-native-splash-screen', path: '../node_modules/react-native-splash-screen'

  permissions_path = '../node_modules/react-native-permissions/ios'

  pod 'Permission-AppTrackingTransparency', path: "#{permissions_path}/AppTrackingTransparency"
  pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications"

  pod 'RNFS', path: '../node_modules/react-native-fs'

  pod 'RNSVG', :path => '../node_modules/react-native-svg'

  pod 'react-native-webview', :path => '../node_modules/react-native-webview'

  post_install do |installer|
    react_native_post_install(installer)
    __apply_Xcode_12_5_M1_post_install_workaround(installer)

    installer.pods_project.build_configurations.each do |config|
      config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
    end

    # Workaround `Cycle inside FBReactNativeSpec` error for react-native 0.64
    # Reference: https://github.com/software-mansion/react-native-screens/issues/842#issuecomment-812543933
    installer.pods_project.targets.each do |target|
      next unless target.name&.eql?('FBReactNativeSpec')

      target.build_phases.each do |build_phase|
        if build_phase.respond_to?(:name) && build_phase.name.eql?('[CP-User] Generate Specs')
          target.build_phases.move(build_phase, 0)
        end
      end
    end
  end

  pod 'RNVectorIcons', path: '../node_modules/react-native-vector-icons'

  pod 'FirebaseCore', modular_headers: true
  pod 'FirebaseCoreInternal', modular_headers: true
  pod 'GoogleUtilities', modular_headers: true
end

android/build.gradle

No response

android/app/build.gradle

No response

android/settings.gradle

No response

AndroidManifest.xml

No response

mikehardy commented 4 months ago

I won't have time to help you troubleshoot, sorry. It's possible to add more echo statements in this file and see what's going on as it evaluates things in order to find out why it doesn't like or cannot find your app.json

https://github.com/invertase/react-native-google-mobile-ads/blob/main/ios_config.sh

Note that you need to run pod install after making changes to it, that file is injected into the project config file as a thing that xcodebuild should run, and pod install is how that happens so if you make a change to ios_config.sh and do not run pod install, it will be very confusing why your change did not take effect...

renatomserra commented 4 months ago

amazing thanks @mikehardy i was missing this step Note that you need to run pod install after making changes to it to successfully be able to debug myself. i spent 3h changing and tyring to figure out why my changes to the file werent applying :D

mikehardy commented 4 months ago

@renatomserra I feel your pain. I have also wasted time not realizing why changes weren't being applied.

550 is a note added to the file, I should have done that long ago, why didn't I think of it before?

What do you think

renatomserra commented 4 months ago

@mikehardy i think i would have missed that comment still, id suggest instead adding it to the logs in cases of failure as tahts when devs will care about it.

So i "sorted" my issue but im not sure why.

changing file lookup maxdepth from 2 to 1 found the right app.json.

_SEARCH_RESULT=$(find "$_CURRENT_SEARCH_DIR" -maxdepth 1 \( -name ${_JSON_FILE_NAME} -o -name ${_JS_APP_CONFIG_FILE_NAME} \) -print | /usr/bin/head -n 1)

I noticed that that in the log i posted above it says it found app.json in /web-build but there is no such directory. Im wondering if it picked something up from node modules.

mikehardy commented 4 months ago

I noticed that that in the log i posted above it says it found app.json in /web-build but there is no such directory. Im wondering if it picked something up from node modules.

... 🤔 that is really strange - if you can figure out the what+why there and we can harden the script up that may help others in the future

@mikehardy i think i would have missed that comment still, id suggest instead adding it to the logs in cases of failure as tahts when devs will care about it.

Unfortunately I'm not sure where exactly I'd do that - the problem with Xcode build logs is that even I have a hard time figuring out exactly where the build logs are so I think a lot of the dev population would miss that as well, additionally there's no failure most of the time - it is just the old script running not the new one you haven't installed with pod install yet - how to detect that and only emit something then, in a place people can see it?

I am going to go ahead and merge the comment as it does no harm at least and could help but I can't think of a better way yet. If you can I'm definitely open to suggestions

Glad you're moving along either way

micaeldias commented 3 months ago

@mikehardy I had this error with an app that has Let's in the name, after I removed the apostrophe it worked. Hope that helps resolving it.

info: -> RNGoogleMobileAds build script started
info: 1) Locating app.json file:
info:      (1 of 2) Searching in '/home/Repositories/lets' for a app.json/app.config.js file.
info:      app.json found at /home/Repositories/lets/app.json
-e:3: syntax error, unexpected local variable or method, expecting ')'
    "name": "Let's",
                 ^
-e: compile error (SyntaxError)
github-actions[bot] commented 2 months ago

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.