android 如何在Expo和Expo Go中使用原生谷歌移动广告?

z31licg0  于 2023-01-24  发布在  Android
关注(0)|答案(3)|浏览(290)

如何在Expo和Expo Go中使用原生Google移动广告?(例如横幅广告)

  • 在世博会的背景下提供一个最小的例子将是非常感谢的。

截至2022年5月,所有在线Google文档都提到expo-ads-admob,但Expo文档现在提到expo-ads-admob已被弃用,并打算在v46中删除对该模块的支持。
Expo recommends using react-native-google-mobile-ads.当我将该模块集成到项目中时,当我通过Expo Go(和Metro)启动应用程序时,我会崩溃。

Invariant Violation: requireNativeComponent: "RNGoogleMobileAdsBannerView" was not found in the UIManager.                                                                                  
                                                                                              
This error is located at:                                                                     
    in RNGoogleMobileAdsBannerView (created by BaseAd)                                        
    in BaseAd (created by BannerAd)                                                           
    in BannerAd (created by App)                                                              
    in RCTView (created by View)                                                              
    in View (created by App)                                                                  
    in App (created by ExpoRoot)
    in ExpoRoot
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer
    in main(RootComponent)
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:95:4 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:141:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/expo-error-recovery/build/ErrorRecovery.fx.js:12:21 in ErrorUtils.setGlobalHandler$argument_0

我认为这个错误与链接有关,但我明确地试图让它在Expo中工作,而不是纯粹的React Native。
海事组织,原因为什么这个React原生谷歌移动广告模块是不兼容的世博会去将足以作为一个答案。
要重新迭代:我如何在Expo和Expo Go中使用react-native-google-mobile-ads?如果能在Expo的背景下举一个最小的例子,我将非常感激。

e4eetjau

e4eetjau1#

要在Expo管理的工作流中使用react-native-google-mobile-ads,您需要将EAS作为“开发客户端”来构建项目。开发客户端提供与Expo Go类似的功能和便利。主要区别在于您需要在本地设置工作EAS构建环境,或者使用Expo提供的云构建。
假设您有本地EAS构建设置,并希望构建Android:

# Install the ad module
expo install react-native-google-mobile-ads

# Install the dev-client module
expo install expo-dev-client

# Build the dev-client (as an APK)
eas build --platform android --profile development --local

# Note: Install the built APK into emulator or device.

# Start the expo service for the dev client
expo start --dev-client --lan

安装APK并设置服务后,您可以通过Expo Go扫描二维码加载应用程序。
注意:不要将react-native-google-mobile-ads配置放在app.json配置的expo部分,这个错误让我不得不深入挖掘react-native-google-mobile-ads的build.gradle代码。

// app.json
{
  "expo": {
  // ...
  },
  "react-native-google-mobile-ads": {
    "android_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx",
    "ios_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx"
  }
}
chhkpiq4

chhkpiq42#

expo的V46有一些问题,我用过expo的V45,它工作得很完美。

but5z9lq

but5z9lq3#

您必须完成此步骤才能进行展示

npx pod-install
npx react-native run-ios

# For Android
npx react-native run-android

# For expo users not using EAS
npx expo prebuild

# For expo users using EAS
npx eas-cli build --profile development

相关问题