android 不变违反:TurboModuleRegistry.getEnforcing(...):'RNGoogleMobileAdsModule',在react native中集成admob

ax6ht2ek  于 11个月前  发布在  Android
关注(0)|答案(1)|浏览(155)

我是新的React Native,我想货币化我的应用程序,所以我集成Admob在React Native,我创建了我的应用程序使用npx create-react-native-app命令,我试图看到youtube,谷歌,chatgpt,吟游诗人,但没有任何工作,这是我最后的希望,请帮助我这里是我的代码,
app.json
x1c 0d1x的数据
Copybase.js -我正在测试我的广告的文件,但从过去2天没有显示

import { Animated, Dimensions, Image, Pressable, StyleSheet, Text, View } from 'react-native';
import React, { useRef } from 'react';
import Header from '../components/Header';
import { useThContext } from '../reducon/context';
import { Linking } from 'react-native';
import { BannerAd, BannerAdSize, TestIds } from 'react-native-google-mobile-ads';

const adUnitId = __DEV__ ? TestIds.BANNER : 'ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx';

export default Copybase = ({ navigation }) => {

  const animation = useRef(new Animated.Value(1)).current;
  const bgColor = useRef(new Animated.Value(0)).current;

  const handlePressIn = () => {
    Animated.spring(animation, {
      toValue: 0.97,
      duration: 200,
      useNativeDriver: true,
    }).start();
    Animated.timing(bgColor, {
      toValue: 1,
      duration: 200,
      useNativeDriver: true,
    }).start();
  }
  const handlePressOut = () => {
    Animated.spring(animation, {
      toValue: 1,
      duration: 200,
      useNativeDriver: true,
    }).start();
    Animated.timing(bgColor, {
      toValue: 0,
      duration: 200,
      useNativeDriver: true,
    }).start();
    Linking.openURL(info.link);
  }

  const { info } = useThContext();

  const backgroundColor = bgColor.interpolate({
    inputRange: [0, 1],
    outputRange: ['#749b38', '#648630'],
  })

  return (
    <View>
      <Header navi={navigation} text={'BASE LAYOUT'} BackButton={true} />
      <View style={styles.container}>
        <Image style={styles.image} source={info.image} />
        <Pressable onPressIn={() => { handlePressIn() }} onPressOut={() => { handlePressOut() }}>
          <Animated.View style={[styles.copyButton, { transform: [{ scale: animation }], backgroundColor: backgroundColor }]}>
            <Text style={styles.copyButtonText}>COPY LAYOUT</Text>
          </Animated.View>
        </Pressable>
      </View>
      <BannerAd
        unitId={TestIds.BANNER}
        size={BannerAdSize.BANNER}
        requestOptions={{
          requestNonPersonalizedAdsOnly: true,
        }}
      />
    </View>
  )
}
const styles = StyleSheet.create({
  container: {
    height: '100%',
    alignItems: 'center',
    backgroundColor: '#f9f9f9',
  },
  image: {
    width: Dimensions.get('window').width,
    height: 300,
    resizeMode: 'contain',
  },
  copyButton: {
    marginTop: 40,
    backgroundColor: '#749b38',
    padding: 12,
    borderRadius: 3,
    shadowColor: "#000000",
    shadowOffset: {
      width: 0,
      height: 1,
    },
    shadowOpacity: 0.16,
    shadowRadius: 1.51,
    elevation: 6,
  },
  copyButtonText: {
    color: '#fff',
    fontWeight: '700',
    fontSize: 18,
  }
});

字符串
我所犯的错误--

Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNGoogleMobileAdsModule' could not be found. Verify that a module by this name is registered in the native binary., js engine: hermes
at node_modules\react-native\Libraries\Core\ExceptionsManager.js:null in reportException
at node_modules\react-native\Libraries\Core\ExceptionsManager.js:null in handleException
at node_modules\react-native\Libraries\Core\setUpErrorHandling.js:null in handleError
at node_modules\expo\build\errors\ExpoErrorManager.js:null in createErrorHandler
at node_modules\expo\build\errors\ExpoErrorManager.js:null in <anonymous>
at node_modules\@react-native\js-polyfills\error-guard.js:null in ErrorUtils.applyWithGuard
at node_modules\metro-runtime\src\polyfills\require.js:null in guardedLoadModule
at http://192.168.29.76:19000/index.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:null in metroRequire
at http://192.168.29.76:19000/index.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:null in global

beq87vna

beq87vna1#

我遇到了同样的错误,问题是使用expo go来运行我的应用程序。你必须做的是使用eas build构建应用程序后,你必须从eas下载构建的应用程序,然后将其安装在你的设备或模拟器上。然后从vs代码运行你的开发服务器,并运行你下载的应用程序。请参阅this从youtube或here是相同的视频从博览会doc如果你想进一步阅读它。我希望这对你有帮助:)
在你做这个修复你将运行到另一个错误,你需要降级安装的节点版本到当前的LTS版本,在这个答案的时间是18.17.0.要遵循此修复程序,请查看此

相关问题