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

[📚] Expo configuration for SDK 51 #588

Closed raul-potor closed 1 week ago

raul-potor commented 1 week ago

Documentation Feedback

Hello,

Today I was upgrading my project from Expo SDK 50 to Expo SDK 51, and I had a warning in the console:

Warning: Root-level "expo" object found. Ignoring extra key in Expo config: "react-native-google-mobile-ads"

This warning was not present on SDK 50, and the key was placed outside the expo object as stated in the docs

After some research, I found this post about the migration from the root expo object.

I believe the documentation should be updated in this case, as it still states that the react-native-google-mobile-ads should be placed outside the expo block:

// <project-root>/app.json
{
  "expo": {
    // ...
  },
  "react-native-google-mobile-ads": {
    "android_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx",
    "ios_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx"
  }
}
Lamonarch87 commented 1 week ago

Have you ever tried building with that config code inside "extra"?

Because I'm getting an error saying that the app_id is missing. (on expo SDK 50)

On expo 51:

Where: Build file '/home/expo/workingdir/build/node_modules/react-native-google-mobile-ads/android/build.gradle' line: 82

(edited)

raul-potor commented 1 week ago

Nope, what I ended up doing was removing the root expo object from app.json

So before it looked like this:

{
  "expo": {
    "name: "foo",
    ...
  },
  "react-native-google-mobile-ads": {
    "android_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx",
    "ios_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx"
  }
}

and now it looks like this

{
  "name: "foo",
  ...
  "react-native-google-mobile-ads": {
    "android_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx",
    "ios_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx"
  }
}

And now the warning is gone and the ads seem to work well (only tested locally with the test units). Don't know if this is the right way to do it or not on SDK 51

dylancom commented 1 week ago

Would be great if you can submit a PR to update the docs!

raul-potor commented 1 week ago

Hmm, I actually don't think this is a reliable solution, the expo-doctor check fails while validating the app.json schema with the following error:

• should NOT have additional property 'react-native-google-mobile-ads'.

So I actually think the better approach is to keep the react-native-google-mobile-ads config inside extra as @Lamonarch87 suggested. I mean, this approach works, the ads are displayed properly, but because o that error I don't think it's a long-term solution for now, just a workaround.

I see there is already a PR in progress for that: https://github.com/invertase/react-native-google-mobile-ads/pull/584

Lamonarch87 commented 1 week ago

Hmm, I actually don't think this is a reliable solution, the expo-doctor check fails while validating the app.json schema with the following error:

• should NOT have additional property 'react-native-google-mobile-ads'.

So I actually think the better approach is to keep the react-native-google-mobile-ads config inside extra as @Lamonarch87 suggested. I mean, this approach works, the ads are displayed properly, but because o that error I don't think it's a long-term solution for now, just a workaround.

I see there is already a PR in progress for that: #584

I did not suggested to put inside "extra". It is written in Expo Documentation at the bottom of the link provided by you, but for me it's not working.

Even if expo-doctor is saying that is wrong, putting it outside of "expo" is the only way to build successfully for me atm.

claudiofus commented 4 days ago

I have an iOS and Android app, with root > expo > react-native-google-mobile-ads, I'm able to build successfully for iOS with EAS and locally. The same app.json fails for Android:

ERROR: react-native-google-mobile-ads requires an 'android_app_id' property inside a 'react-native-google-mobile-ads' key in your app.json.
  No android_app_id property was found in this location. The native Google Mobile Ads SDK will crash on startup without it.

I've tried to include react-native-google-mobile-ads in extra or keep both inside and outside but isn't working for Android.

Last chance is patch-package as suggested but I didn't had time to test it.

joshkitt commented 13 hours ago

I see that this issue is closed, but I'm not clear on what the solution is. Can you please provide a quick example of an app.json file that works for Expo SDK 51?