How to use react-native-google-mobile-ads with Expo?

Viewed 568

I have an Expo app that works well. Now, I would like to add a few ads before publishing it on Play Store in order to make a few bucks. Expo says their in-house ads package is deprecated and that I must use react-native-google-mobile-ads.

Because react-native-google-mobile-ads is a native package, it means I need to perform special tasks, and it's a bit unclear on how to proceed from here.

From what I've understood, I need to:

  • install expo-dev-client and react-native-google-mobile-ads

  • add react-native-google-mobile-ads in the app.json 's expo plugin

"expo": { "plugins": ["react-native-google-mobile-ads"]}

  • add my adMob api key in app.json

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

  • create an account on https://expo.dev and run eas login in my terminal

  • then run eas build --profile development --platform android to generate a build

  • since expo-go won't work anymore because of the native package, I won't be able to run the app on a real phone. I will have to finish the development on an android simulator by running expo start --dev-client and press a to open the app on the android emulator.

  • then add the code to display the ads.

  • Once it's done, run eas build --platform android to create a build

  • follow the long process to upload my first build to the Play Console

  • Publish it as a beta app, send the link to adMob review.

  • Once adMob says all's good, I can publish the app for good on the PlayStore.

It's not a smooth process... I don't know why Expo decided to remove such a common package! Can someone confirm to me this is the right process? Or maybe there is a simpler approach, with a different library?

1 Answers

I've found the solution. Here are the steps to take:

  • yarn add react-native-google-mobile-ads
  • add your adMob credential in app.json (out of the expo object)
  • suscribe to Expo's EAS.
  • run eas login in your terminal and enter your credentials
  • make sure you're correctly logged-in by running eas whoami
  • make sure you have Android studio and SDK 31 installed
  • make sure you have Java 11 Zulu installed
  • run expo install expo-dev-client
  • if you want to build for ios, run eas device:create. Else, move on to the next line.
  • run eas build --platform android --profile development --local (you may replace android by ios or just run the command without the --platform flag. I added --local because the cloud build wasn't working for unknown reasons). This will create a build on your machine.
  • drag and drop the build (.apk for android) directly on your simulator. This will install it on it.
  • run expo start --dev-client
  • your app is now running on your phone. Congratulations. The fast refresh is enabled and you may have some fun.
  • once you're happy with the coding, start the build again.
Related