react-native-admob icon indicating copy to clipboard operation
react-native-admob copied to clipboard

[Android] Application crashes on start

Open mattveraldi opened this issue 6 years ago • 19 comments

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.

mattveraldi avatar Jan 05 '19 18:01 mattveraldi

Hi there,

Exact same problem here. React Native Environment Info: System: OS: Windows 10 CPU: x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz Memory: 2.91 GB / 15.86 GB Binaries: Yarn: 1.5.1 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 6.2.0 - C:\Program Files\nodejs\npm.CMD IDEs: Android Studio: Version 3.2.0.0 AI-181.5540.7.32.5056338

Package.json infos : "react": "^16.5.0", "react-native": "^0.57.1", "react-native-admob": "^2.0.0-beta.5",

It compiles but crashes on emulator when it tries to launch the app :(

grean avatar Jan 07 '19 13:01 grean

I tried that solution and it works great : https://github.com/sbugert/react-native-admob/issues/370

grean avatar Jan 07 '19 17:01 grean

I tried that solution and it works great : #370

Thank you, unfortunately It didn't work for me, it still crashes

mattveraldi avatar Jan 07 '19 22:01 mattveraldi

I finally found a solution that works for me: I figured out that in the build.gradle file placed in react-native-admob/android/ targetSdkVersion was 22, but in my app's build.gradle is 26 so I changed the admob so that they match. targetSdkVersion 26 Also, i hardcoded the dependencies of admob's build.gradle so that play-service-ads is always set to the 16.0.0 version. compile 'com.google.android.gms:play-services-ads:16.0.0'

this worked for me, at least on the emulator. @grean let me know if it works for you aswell.

EDIT: doesn't work on real devices

mattveraldi avatar Jan 14 '19 21:01 mattveraldi

Here my context : compileSdkVersion 27 buildToolsVersion "27.0.3" minSdkVersion 21 targetSdkVersion 27 I'm not expert in gradle configuration and i use lots of dependencies in my project. So i just can tell you that it works for me since i've added the good line in AndroidManifest.xml I have to change the version of a line too : implementation 'com.google.android.gms:play-services-auth:16.0.1' from version 15.0.0 to 16.0.1

grean avatar Jan 15 '19 12:01 grean

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,

ad7090 avatar Jan 15 '19 14:01 ad7090

@AMINDRH91 thank you so much it worked for me

AmirDoreh avatar Jan 15 '19 14:01 AmirDoreh

I tried that solution and it works great : #370

Hi I tried this solution but it did not work until I changed the admob id from this ca-app-pub-3940256099942544/6300978111 to this ca-app-pub-3940256099942544~6300978111 in AndroidManifest.xml Pay attention to tilt. I do know not if it is right or not but changing slash to title worked for me.

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

Delwalt avatar Jan 23 '19 06:01 Delwalt

@AMINDRH91 thank you i worked for me

wandriputra avatar Jan 26 '19 15:01 wandriputra

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

mattveraldi avatar Jan 26 '19 23:01 mattveraldi

Damn it's the 5th time i uninstall / install this module. I forgot to hardcode the play services module . Thanks for the fix i was going insane.

Maybe we will need to wait for the react-native-firebase to release the standalone module of admob in v6.0.0 but it can be months until that...

elMuso avatar Feb 10 '19 17:02 elMuso

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

kufii avatar Feb 17 '19 03:02 kufii

@mattveraldi thank you so much for saving my life haha! I've tried plenty of solutions but nothing worked for me. Your solution worked perfectly!

ghost avatar May 25 '19 15:05 ghost

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

this is not working for me, actually i've did all but nothing works

lefrankleal avatar Jun 08 '19 07:06 lefrankleal

You could use your own fork or use my fork to avoid hardcoding things

"react-native-admob": "git+ssh://[email protected]:smakosh/react-native-admob.git",

smakosh avatar Aug 26 '19 03:08 smakosh

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.

aswincheriyala avatar Jan 29 '20 05:01 aswincheriyala

implementation "androidx.annotation:annotation:1.1.0" . <-- add implementation 'com.google.android.gms:play-services-ads:16.0.0'

This worked for me.

levimake avatar Feb 07 '20 18:02 levimake

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 ~

hkniyi avatar Jun 26 '20 19:06 hkniyi

@aswincheriyala thank you.

sametpalitci avatar Jul 07 '20 06:07 sametpalitci