Admob无法加载,并显示错误“ at nativeToJSError”-React Native

时间:2019-03-01 02:49:17

标签: android react-native admob

问题

我目前在应用程序的产品版本中运行应用程序,但是由于某些原因而未对我的代码进行任何更改,现在在Android上测试我的React Native时出现以下错误。我在计算机上的android模拟器和连接到计算机的android设备上都尝试过。

在今天之前,它在iOS上运行良好,在Android上运行良好。

我在几周前启用了广告,因此这不是库存不足的问题,在这种情况下,调试器会显示为库存不足

如果有人提出建议,那就太好了!这使我无法为用户推送重要更新。

错误

result     at nativeToJSError (blob:http://localhost:8081/6fcdf141-5854-4a90-ba10-5e5c347584ab:105783:17)
    at AdMobComponent._this.onBannerEvent (blob:http://localhost:8081/6fcdf141-5854-4a90-ba10-5e5c347584ab:106684:64)
    at Object.invokeGuardedCallbackImpl (blob:http://localhost:8081/6fcdf141-5854-4a90-ba10-5e5c347584ab:7899:16)
    at invokeGuardedCallback (blob:http://localhost:8081/6fcdf141-5854-4a90-ba10-5e5c347584ab:7990:37)
    at invokeGuardedCallbackAndCatchFirstError (blob:http://localhost:8081/6fcdf141-5854-4a90-ba10-5e5c347584ab:7994:31)
    at executeDispatch (blob:http://localhost:8081/6fcdf141-5854-4a90-ba10-5e5c347584ab:8188:9)
    at executeDispatchesInOrder (blob:http://localhost:8081/6fcdf141-5854-4a90-ba10-5e5c347584ab:8208:11)
    at executeDispatchesAndRelease (blob:http://localhost:8081/6fcdf141-5854-4a90-ba10-5e5c347584ab:8303:11)
    at executeDispatchesAndReleaseTopLevel (blob:http://localhost:8081/6fcdf141-5854-4a90-ba10-5e5c347584ab:8312:16)
    at forEachAccumulated (blob:http://localhost:8081/6fcdf141-5854-4a90-ba10-5e5c347584ab:8295:14)

错误传回的参数

Arguments [callee: ƒ, Symbol(Symbol.iterator): ƒ]
 callee: ƒ render()
  arguments: null
  caller: null
  length: 0
  name: "render"
  prototype: {constructor: ƒ}
  __proto__: ƒ ()
  [[FunctionLocation]]: Admob.js:33
  [[Scopes]]: Scopes[3]
  length: 0
 Symbol(Symbol.iterator): ƒ values()
  arguments: [Exception: TypeError: 'caller', 'callee', and  'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.invokeGetter (<anonymous>:2:14)]
  caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.invokeGetter (<anonymous>:2:14)]
  length: 0
  name: "values"
  __proto__: ƒ ()
  [[Scopes]]: Scopes[0]
  __proto__: Object

Admob组件代码 该代码完全与react-native应用程序中的代码相同,我所做的唯一更改是删除了应用程序和单元ID。我已检查以确保它们正确无误。

  import React, {Component} from 'react';
    import {
    StyleSheet,
    View,
    Text,
    Dimensions,
  Image,
  TouchableWithoutFeedback
} from 'react-native';

import firebase from 'react-native-firebase';


const Analytics = firebase.analytics()
const Admob = firebase.admob()
const Banner = firebase.admob.Banner;
const AdRequest = firebase.admob.AdRequest;
const request = new AdRequest().addTestDevice()


export default class AdmobComponent extends React.Component{

  constructor(props){
    super(props);
    Admob.initialize('Removed for privacy')
    this.state = {};

  }
  onBannerPress() {
    console.log('add button butotn pushed')
    Analytics.logEvent('banner_click')

  }

  render(){
    return(
      <View>
        <TouchableWithoutFeedback
          style={styles.adMobTouch}
          onPress={() => this.onBannerPress()}

        >
          <Banner
            size={"SMART_BANNER"}
            unitId={'Removed for private'}
            request={request.build()}
            onAdLoaded={() => {
              console.log('Advert loaded');
            }}
            onAdFailedToLoad={(result) => {
              console.log('result', result)
              console.log('Ad failed to load', arguments)
            }}
          />
        </TouchableWithoutFeedback>
      </View>
    )
  }
}

2 个答案:

答案 0 :(得分:0)

我也遇到了同样的错误,实际上这不是一个错误,您只需要制作一个正式发布的apk,当用户点击Admob的次数如此之多时,admob将开始展示真实的广告,与此同时仍然会在开发模式下看到此错误,但在您的apk的生产模式下仍然可以正常工作,只需制作发布apk,当您的应用中有太多广告请求时,广告就会在24小时内开始投放!..

更多信息===> https://github.com/invertase/react-native-firebase/issues/2054

答案 1 :(得分:0)

出于开发目的,unitId必须是预定义值之一https://developers.google.com/admob/android/test-ads?hl=en-GB

  1. 横幅:
    • ca-app-pub-3940256099942544/6300978111
  2. 非页内广告:
    • ca-app-pub-3940256099942544/1033173712
  3. 非页内视频:
    • ca-app-pub-3940256099942544/8691691433
  4. 奖励视频:
    • ca-app-pub-3940256099942544/5224354917
  5. 高级母语:
    • ca-app-pub-3940256099942544/2247696110
  6. 本地高级视频
    • ca-app-pub-3940256099942544/1044960115