0

I tried to integrate google admob with react-native 0.57 but I had some problems. Can someone help me writing all the steps to have a working google admob banner in react-native?

P.S. : I am developing app for android devices

1 Answers1

0

Here are a great text about this https://medium.com/@TarikHajji/add-admob-to-react-native-app-5b1e91be459

Sergio Clemente
  • 809
  • 8
  • 12
  • Thank you for your answer. I forget to say that I develop my app for android devices, can you help me ? – Daniele Menchetti Nov 14 '18 at 23:32
  • Sure. You install react-native-admob plugin and configured with your account data ? What error appear? – Sergio Clemente Nov 15 '18 at 00:44
  • Here what I've done: 1) react-native init testAd --version 0.55.2 2) npm i react-native-admob -S 3) react-native link 4) react-native run-android ERROR: A problem occurred configuring project ':app'. > Could not resolve all dependencies for configuration ':app:_debugApk'. > A problem occurred configuring project ':react-native-admob'. > Could not resolve all dependencies for configuration ':react-native-admob:_debugPublishCopy'. > Could not find com.google.android.gms:play-services-ads-lite:12.0.1. – Daniele Menchetti Nov 15 '18 at 20:56
  • Try npm install --save react-native-admob@next , react-navigation link react-native-admob – Sergio Clemente Nov 15 '18 at 22:20
  • Having the same problemo :( – Daniele Menchetti Nov 15 '18 at 22:28
  • So... yout can try use react-native-firebase plugin to this 1 - npm install --save react-native-firebase 2 - npm link react-native firebase 3- Create a firebase account for your app. 4- go to firebase console, project overview add app 5- download file google-services.json 6- put file in root_project/android/app/ – Sergio Clemente Nov 17 '18 at 13:40
  • 7 - edit android/build.gradle buildscript { // ... dependencies { // ... classpath 'com.google.gms:google-services:4.0.1' } } – Sergio Clemente Nov 17 '18 at 13:48
  • 8 - edit app/build.gradle apply plugin: 'com.google.gms.google-services' Dependencies { // This should be here already implementation project(':react-native-firebase') // Firebase dependencies implementation "com.google.android.gms:play-services-base:16.0.1" implementation "com.google.firebase:firebase-core:16.0.4" implementation "com.google.firebase:firebase-ads:15.0.1" – Sergio Clemente Nov 17 '18 at 13:48
  • 9 - edit android/app/src/main/java/com/[app name]/MainApplication.java import io.invertase.firebase.admob.RNFirebaseAdMobPackage; // <-- Add this line protected List getPackages() { return Arrays.asList( new MainReactPackage(), new RNFirebasePackage(), new RNFirebaseAdMobPackage() // <-- Add this line This is it... – Sergio Clemente Nov 17 '18 at 13:49
  • usage: import firebase from 'react-native-firebase'; firebase.admob().initialize('ca-app-pub-xxx'); const Banner = firebase.admob.Banner; const AdRequest = firebase.admob.AdRequest; const request = new AdRequest(); request.addKeyword('foo'); { console.warn('loaded'); }} onAdFailedToLoad={(error) => { console.warn(error.message); }} /> reference : https://rnfirebase.io/docs/v5.x.x/admob/android for me it's ok in a test app – Sergio Clemente Nov 17 '18 at 13:52
  • Oh thank you! I'm going to try this now. Which react-native version do you use? – Daniele Menchetti Nov 17 '18 at 13:58
  • I use with react-native 0.57 – Sergio Clemente Nov 17 '18 at 15:21
  • I follow what you said to me and I had this error on Node: https://drive.google.com/open?id=1L1QGWvwvqwhkKRV2eI-AuWzroIDjLNBS. On my other react-native apps the error does not exists and everything work well. – Daniele Menchetti Nov 18 '18 at 10:24
  • Here I upload pics about both Node error and my C:/ folders. https://drive.google.com/open?id=1d3TaU73OcO4zm71IXs5k46QOVSPAgcCK. Tahnk you for your help! :) – Daniele Menchetti Nov 18 '18 at 10:42
  • Try npm start -- --reset-cache – Sergio Clemente Nov 18 '18 at 14:50
  • Same problem :( https://drive.google.com/open?id=1d3TaU73OcO4zm71IXs5k46QOVSPAgcCK – Daniele Menchetti Nov 18 '18 at 15:08
  • I solved this error and now I get this "import" error in the last photo of my drive directory ('Cattura4') : https://drive.google.com/open?id=1d3TaU73OcO4zm71IXs5k46QOVSPAgcCK – Daniele Menchetti Nov 19 '18 at 22:15
  • the error say that you have two or more firebase import. – Sergio Clemente Nov 19 '18 at 22:51
  • I wrote import firebase only once, how can I do? – Daniele Menchetti Nov 20 '18 at 06:52
  • please, copy all content of your file . – Sergio Clemente Nov 20 '18 at 10:13
  • All files except node_modules folder? – Daniele Menchetti Nov 20 '18 at 10:16
  • Ok I solved the problem, now with an example API (ca-app-pub-3940256099942544/6300978111) the app show the banner perfectlybut with my API I get this error: "The ad request was successful, no ad was returned due to lack of ad inventory". Can you list me how get an API of Ad Mob and link it to frebase step by step?? – Daniele Menchetti Nov 20 '18 at 21:19
  • it's good. The code is correct. the error is in your ads. In some cases is need wait some hours or days to campaing start. The point is, if it's ok with the exemple code, it's all ok!. – Sergio Clemente Nov 21 '18 at 14:44
  • I have the same problem after 3 days, where can I find this two 'KEYS' ?? firebase.admob().initialize('KEY 1'); and { console.warn('loaded'); }} onAdFailedToLoad={(error) => { console.warn(error.message); }} /> can you post me some screen about it ?? Do I have to register a credit card to let API KEY works ? – Daniele Menchetti Nov 23 '18 at 20:57
  • Can you Sergio help me ?? I create my banner and get its ID 5/6 days ago, but nothing changes... – Daniele Menchetti Nov 25 '18 at 19:17
  • Hey, sorry, but i don't have any idea what can be the problem. Maybe your ad in admob is incorrect. I search in web and don't found any good answer for this. Only what i just say.... Se see here https://stackoverflow.com/questions/8778756/onfailedtoreceiveadad-request-successful-but-no-ad-returned-due-to-lack-of-ad It maybe help u. – Sergio Clemente Nov 25 '18 at 23:50