DoneDeal0
DoneDeal0

Reputation: 6257

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

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:

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

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

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?

Upvotes: 6

Views: 2987

Answers (1)

DoneDeal0
DoneDeal0

Reputation: 6257

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.

Upvotes: 6

Related Questions