RNFirebaseAdMobPackage 在本机版本 0.60.4 中引发错误 [英] RNFirebaseAdMobPackage throws error in react-native version 0.60.4

查看:56
本文介绍了RNFirebaseAdMobPackage 在本机版本 0.60.4 中引发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I just upgraded my React Native application to version 0.60.4. Here i'm trying to add react-native-firebase version ^5.2.3 and facing the following error:

我试过替换

import io.invertase.firebase.RNFirebaseAdMobPackage;

import io.invertase.firebase.RNFirebasePackage;

还有

new RNFirebaseAdMobPackage();

new RNFirebasePackage();

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

in PackageList.java. But so far no luck. What else can i do to solve the issue?

推荐答案

按顺序检查设置.

  • 为了让 Android 解析这个文件,添加 google-servicesgradle 插件作为项目级别中项目的依赖项build.gradle 文件:
buildscript {
  // ...
  dependencies {
    // ...
    classpath 'com.google.gms:google-services:4.2.0'
  }
}

  1. 要将插件应用到您的项目,请将以下内容添加到 VERY您的应用程序 android/app/build.gradle 文件的底部:
  1. To apply the plugin to your project, add the following to the VERY BOTTOM of your app android/app/build.gradle file:

    apply plugin: 'com.google.gms.google-services'

  1. Firebase 模块需要作为项目依赖项安装.在 android/app/build.gradle 文件中,添加以下内容:
  1. The Firebase modules need to be installed as project dependencies. In the android/app/build.gradle file, add the following:

    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"

      ...

  1. 由于 Android Firebase v12+ 中的一些重大更改库,您至少需要将 Gradle 版本升级到v4.4 并进行如下一些其他调整:

1) 在android/gradle/wrapper/gradle-wrapper.properties中,更新gradle URL为gradle-4.4-all.zip2) 在 android/build.gradle 中检查您是否在 buildScript 存储库部分指定了 google():

1) In android/gradle/wrapper/gradle-wrapper.properties, update the gradle URL to gradle-4.4-all.zip 2) In android/build.gradle check that you have google() specified in the buildScript repositories section:

buildscript {
    repositories {
        google()  // <-- Check this line exists and is above jcenter
        jcenter()
        // ...
    }
    // ...
}

3) 在 android/build.gradle 中更新 Android 构建工具到版本 3.4.1:

3) In android/build.gradle update Android build tools to version 3.4.1:

classpath 'com.android.tools.build:gradle:3.4.1'

11.2.0 以后的 Google Play 服务需要从 Google 的 Maven 存储库下载其依赖项,因此将所需的引用添加到项目级别的存储库部分 build.gradle (android/build.gradle):

Google Play services from 11.2.0 onwards require their dependencies to be downloaded from Google's Maven respository so add the required reference to the repositories section of the project level 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"
        }
    }
}

  • 在启用 Proguard 的情况下使用 react-native-firebase 时(minifyEnabled true in android/app/build.gradle) 你需要更新您的 proguard-rules.pro 文件 (android/app/proguard-rules.pro) 到包括以下几行:

    • When using react-native-firebase with Proguard enabled (minifyEnabled true in android/app/build.gradle) you need to update your proguard-rules.pro file (android/app/proguard-rules.pro) to include the following lines:

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

      -keep class io.invertase.firebase.** { *; }

      -dontwarn io.invertase.firebase.**

      -dontwarn io.invertase.firebase.**

      RNFirebasePackage 仅向您的应用程序提供对核心功能的访问权限.查看其他模块的安装指南,了解如何使用其他 Firebase 功能.

      The RNFirebasePackage only provides your application with access to Core features. Check out the installation guides on the other modules for how to use other Firebase features.

      请检查是否有这部分.

      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>
      

      这篇关于RNFirebaseAdMobPackage 在本机版本 0.60.4 中引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆