问题
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:
I have tried replacing
import io.invertase.firebase.RNFirebaseAdMobPackage;
With
import io.invertase.firebase.RNFirebasePackage;
And
new RNFirebaseAdMobPackage();
With
new RNFirebasePackage();
in PackageList.java
. But so far no luck. What else can i do to solve the issue?
回答1:
Check the settings in order.
- In order for Android to parse this file, add the google-services
gradle plugin as a dependency to your project in the project level
build.gradle
file:
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:4.2.0'
}
}
- 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'
- 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"
...
- Due to some breaking changes in v12+ of the Android Firebase libraries, you'll need to upgrade your Gradle version to at least v4.4 and make a few other tweaks as follows:
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) In android/build.gradle
update Android build tools to version 3.4.1
:
classpath 'com.android.tools.build:gradle:3.4.1'
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"
}
}
}
When using
react-native-firebase
with Proguard enabled (minifyEnabled true inandroid/app/build.gradle
) you need to update yourproguard-rules.pro
file (android/app/proguard-rules.pro
) to include the following lines:-keep class io.invertase.firebase.** { *; }
-dontwarn io.invertase.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.
Please check if there is this part.
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>
来源:https://stackoverflow.com/questions/57250177/rnfirebaseadmobpackage-throws-error-in-react-native-version-0-60-4