添加 react-native-admob 模块后,React-Native 应用程序在启动时崩溃

React-Native app is crashing on launch after adding react-native-admob module

下面是我的包裹。

{ "name": "wallpaper_rn", "version": "0.1.0", "private": true, "devDependencies": { "babel-preset-react-native-stage-0": "^1.0.1", "jest": "^23.6.0", "jest-react-native": "^18.0.0", "react-test-renderer": "16.3.1" }, "scripts": { "start": "react-native start", "android": "react-native run-android", "ios": "react-native run-ios", "test": "jest" }, "jest": { "preset": "react-native" }, "dependencies": { "prop-types": "^15.6.2", "react": "16.4.1", "react-native": "~0.55.2", "react-native-admob": "^2.0.0-beta.5", "react-native-elements": "^0.19.1", "react-native-fetch-blob": "^0.10.8", "react-native-fs": "^2.11.17", "react-native-share": "^1.1.2", "react-native-splash-screen": "^3.1.1", "react-native-swiper": "^1.5.13", "react-native-vector-icons": "^5.0.0", "react-navigation": "^2.14.1", "react-redux": "^5.0.7", "recyclerlistview": "^1.3.4", "redux": "^4.0.0", "redux-thunk": "^2.3.0" } }

我也试过 react-native-admob (1.3.2) 版本

我刚刚安装了 admob 模块 link。即使在调试模式下,该应用程序在启动时突然开始崩溃。

经过一番查找,得知是Google在2018年10月2日更新了部分库导致了这个错误。我更改了 android/build.gradle 文件:

compile 'com.google.android.gms:play-services-ads:+'

compile 'com.google.android.gms:play-services-ads:15.0.0'

这已经解决了问题。

请在您的项目中添加这一行AndroidManifest.xml

里面<application>

<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="[appid here]"/>

参考:https://github.com/sbugert/react-native-admob/issues/370#issuecomment-429322754