简体   繁体   中英

React Native AdMob Error: undefined is not an object (evaluating '_reactNative.View.propTypes.style')

I tried using react-native-admob package for displaying ads and I followed the instructions in here: https://www.npmjs.com/package/react-native-admob

After setting it up, I'm getting an error:

在此处输入图片说明

Step-1 . Add below line at top in node-modules/react-native-admob/RNAdmobBanner.js and RNPublisherBanner.js

import PropTypes from "prop-types";

Step-2 . Delete these line from both file(May be line no is 48 and 50 respective)

style: View.propTypes.style

note: style property of AdmobBanner is not working at all so you can delete this because this is creating issue.

Step-3 . Change this words in both file

React.PropTypes ===> to ===> PropTypes

old Content=>

bannerSize: React.PropTypes.string,
adUnitID: React.PropTypes.string,
testDeviceID: React.PropTypes.string,
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,

new content should be like this=>

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,

Reference: https://github.com/facebook/react-native/issues/16542#issuecomment-415751870

OR

react-native unlink react-native-admob

npm uninstall react-native-admob

npm install -save react-native-admob@next

Docs: https://github.com/sbugert/react-native-admob

Reference: https://github.com/sbugert/react-native-admob/issues/391#issuecomment-451253909

For, react-native-admob@next , use adSize property instead of bannerSize

从 AdMobBanner 中删除样式道具,然后检查

Install the beta version of this plugin. This problem sorts out in this version. the package.json will look like this.

"react-native-admob": "^2.0.0-beta.6",

Or run this command

npm i react-native-admob@2.0.0-beta.6

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM