react-native - RNFirebaseAdMobPackage 在 native 版本 0.60.4 中引发错误

标签 react-native react-native-firebase

我刚刚将我的 React Native 应用程序升级到版本 0.60.4 .在这里,我想添加 react-native-firebase版本^5.2.3并面临以下错误:

enter image description here

我试过更换

import io.invertase.firebase.RNFirebaseAdMobPackage;


import io.invertase.firebase.RNFirebasePackage;


new RNFirebaseAdMobPackage();


new RNFirebasePackage();

PackageList.java .但到目前为止还没有运气。我还能做些什么来解决这个问题?

最佳答案

按顺序检查设置。

  • 为了让 Android 解析这个文件,添加 google-services
    gradle 插件作为项目级别中项目的依赖项build.gradle文件:
  • buildscript {
      // ...
      dependencies {
        // ...
        classpath 'com.google.gms:google-services:4.2.0'
      }
    }
    
  • 要将插件应用到您的项目,请将以下内容添加到 VERY
    您的应用程序底部 android/app/build.gradle文件:
  •     apply plugin: 'com.google.gms.google-services'
    
  • Firebase 模块需要作为项目依赖项安装。
    android/app/build.gradle文件,添加以下内容:
  •     dependencies {
          // This should be here already
          implementation project(':react-native-firebase')
    
          // Firebase dependencies
          implementation "com.google.android.gms:play-services-base:16.1.0"
          implementation "com.google.firebase:firebase-core:16.0.9"
    
          ...
    
  • 由于 Android Firebase v12+ 中的一些重大更改
    库,您至少需要将 Gradle 版本升级到
    v4.4 并做一些其他的调整如下:

  • 1) 在 android/gradle/wrapper/gradle-wrapper.properties , 将 gradle URL 更新为 gradle-4.4-all.zip2) 在 android/build.gradle检查您是否有 google()在 buildScript 存储库部分中指定:
    buildscript {
        repositories {
            google()  // <-- Check this line exists and is above jcenter
            jcenter()
            // ...
        }
        // ...
    }
    

    3) 在 android/build.gradle将 Android 构建工具更新到版本 3.4.1 :
    classpath 'com.android.tools.build:gradle:3.4.1'
    

    Google Play 服务来自 11.2.0以后需要从 Google 的 Maven 存储库下载它们的依赖项,因此将所需的引用添加到项目级别的存储库部分 build.gradle (android/build.gradle):
    allprojects {
        repositories {
            mavenLocal()
            google() // <-- Add this line above jcenter
            jcenter()
            maven {
                // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
                url "$rootDir/../node_modules/react-native/android"
            }
        }
    }
    
  • 使用时react-native-firebase启用 Proguard
    (minifyEnabled true in android/app/build.gradle ) 你需要更新
    您的 proguard-rules.pro文件 ( android/app/proguard-rules.pro ) 到
    包括以下几行:

    -保持类io.invertase.firebase.** { *; }

    -dontwarn io.invertase.firebase.**
  • RNFirebasePackage只为您的应用程序提供对核心功能的访问。查看其他模块的安装指南,了解如何使用其他 Firebase 功能。

    请检查是否有这部分。
    dependencies {
      // ...
      implementation "com.google.firebase:firebase-ads:17.2.1"
    }
    

    import io.invertase.firebase.admob.RNFirebaseAdMobPackage; // <-- this line
    ...
    ew RNFirebaseAdMobPackage() // <-- this line
    

    <application ...>
    
      <!-- this line as part of new AdMob library process. Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
      <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="YOUR_ADMOB_APP_ID"/>
    
      <uses-library android:name="org.apache.http.legacy" android:required="false"/>  <!-- this line to avoid crashes on Android 9 until AdMob SDK update -->
    
    </application>
    

    关于react-native - RNFirebaseAdMobPackage 在 native 版本 0.60.4 中引发错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57250177/

    相关文章:

    javascript - 如何从react中的渲染函数返回一个空的jsx元素?

    javascript - clearTimeout 在 React Native 上不起作用

    react-native - react native : how to apply shadow and borderRadius to a View?

    javascript - 在 React Native Firebase 中调用 firebase.app() 的目的是什么?

    react-native - React Native Firebase Crashlytics 反混淆

    react-native - 如何使用 react-native-firebase 获取推送通知的数量

    node.js - 无法从 react-script 卸载 webpack

    android - 创建 react native 自定义标题样式?

    reactjs - 执行 createUserWithEmailAndPassword 后,React Native 使用 sendEmailVerification 检查用户电子邮件

    javascript - 即使用户在注册流程中经过身份验证,如何修复 firebase "User is not authorized"错误?