sbugert / react-native-admob

A react-native component for Google AdMob banners
BSD 2-Clause "Simplified" License
1.13k stars 531 forks source link

[Android] Application crashes on start #397

Open mattveraldi opened 5 years ago

mattveraldi commented 5 years ago

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.

grean commented 5 years ago

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 commented 5 years ago

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

mattveraldi commented 5 years ago

I tried that solution and it works great :

370

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

mattveraldi commented 5 years ago

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

grean commented 5 years ago

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

ad7090 commented 5 years ago

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,

AmirDoreh commented 5 years ago

@AMINDRH91 thank you so much it worked for me

Delwalt commented 5 years ago

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"/>

wandriputra commented 5 years ago

@AMINDRH91 thank you i worked for me

mattveraldi commented 5 years ago

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

elMuso commented 5 years ago

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...

kufii commented 5 years ago

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

ghost commented 5 years ago

@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!

lefrankleal commented 5 years ago

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

smakosh commented 5 years ago

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

"react-native-admob": "git+ssh://git@github.com:smakosh/react-native-admob.git",

aswincheriyala commented 4 years ago

Try use androidx

Inside node_modules/react-native-admob =>

In build.gradle

Will remove the errors and crash.

levimake commented 4 years ago

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

This worked for me.

hkniyi commented 4 years ago

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 ~

sametpalitci commented 4 years ago

@aswincheriyala thank you.