react-native-admob: [Android] Application crashes on start

Hi, I have a RN 0.50.3 project running:

	"dependencies": {
		"react": "16.0.0",
		"react-native": "0.50.3",
		"react-native-vector-icons": "^4.4.2",
                "react-native-admob": "^2.0.0-beta.5",
		"react-navigation": "^1.0.0-beta.19",
		"react-redux": "^5.0.6",
		"redux": "^3.7.2",
		"redux-thunk": "^2.2.0"
	},

And I need to set up some admob banners. I installed and linked successfully react-native-admob but my app crashes on startup without giving me any error. it’s very strange and I still can’t figure out why it happens.

It used to work with an old version of react-native-admob, but I lost the package.json file and I can’t remember which version it was.

About this issue

Most upvoted comments

Unfortunately none of this worked for me… But I finally solved my problem so here I post all the steps I followed to make it work: 1- I removed react-native-admob with npm uninstall react-native-admob and I manually unlinked it from the android project; 2- With cd android && gradlew clean && cd .. && react-native run-android I cleaned and runned the app to see if everything was ok. 3- With npm install --save react-native-admob@next I installed the latest release, then I linked it with react-native link, but it still did crash on start but I solved the issue hardcoding google play services’ version on react-native-admob’s build.gradle file that way: compile 'com.google.android.gms:play-services-ads:16.0.0'. 4- On real devices the banner wasn’t showing up. What I found out is that if you have your Admob linked to your app with Google Play, banners only show up with consistency on the release version of the app. Now everything works as it should.

Thank you for your help

hi guys its way its answer

1-npm i --save react-native-admob

2-react-native link react-native-admob

then==>>

3- in manifest <meta-data android:name="com.google.android.gms.ads.YOURpackegName" android:value="ca-app-pub-***********"/>

4- add implementation 'com.google.android.gms:play-services-ads:12.0.0' in gradel

5-in build gradel react-native-admob: compileSdkVersion 26 buildToolsVersion "28.0.3"

6- then you get this error go to node-modules/react-native-admob/RNAdmobBanner.js & node-modules/react-native-admob/ PublisherBanner and Replace line 48 to 86 FIRST ==> import PropTypes from “prop-types”; =>OLD: adViewDidReceiveAd: React.PropTypes.func, didFailToReceiveAdWithError: React.PropTypes.func, adViewWillPresentScreen: React.PropTypes.func, adViewWillDismissScreen: React.PropTypes.func, adViewDidDismissScreen: React.PropTypes.func, adViewWillLeaveApplication: React.PropTypes.func, admobDispatchAppEvent: React.PropTypes.func, ...View.propTypes,

=>NEW: bannerSize: PropTypes.string, adUnitID: PropTypes.string, testDeviceID: PropTypes.string, adViewDidReceiveAd: PropTypes.func, didFailToReceiveAdWithError: PropTypes.func, adViewWillPresentScreen: PropTypes.func, adViewWillDismissScreen: PropTypes.func, adViewDidDismissScreen: PropTypes.func, adViewWillLeaveApplication: PropTypes.func, admobDispatchAppEvent: PropTypes.func,

Try use androidx

Inside node_modules/react-native-admob =>

In build.gradle

  • edit like this ->
implementation "androidx.annotation:annotation:1.1.0" .     <-- add
implementation 'com.google.android.gms:play-services-ads:16.0.0'      <-- add
//implementation 'com.google.android.gms:play-services-ads:+' .   <-- remove
  • replace import android.support.annotation.Nullable with import androidx.annotation.Nullable; inside, RNAdMobBannerViewManager.java, RNAdMobInterstitialAdModule.java, RNAdMobRewardedVideoAdModule.java, RNPublisherBannerViewManager.java

Will remove the errors and crash.

IN …\android\app\src\main\AndroidManifest.xml

CHANGE

<meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-3940256099942544/**********"/>

TO

<meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-3940256099942544~**********"/>

Change: / to ~

@mattveraldi compile 'com.google.android.gms:play-services-ads:16.0.0' fixed it for me, thanks so much

@AMINDRH91 thank you i worked for me