您试图通过调用 firebase.analytics() 使用 android 项目中未安装的 fire 基础模块
You attempted to use a fire base module that's not installed on your android project by calling firebase.analytics()
我已经在我的 React Native 应用程序中安装了 firebase,我需要 firebase 分析模块。
app/build.gradle:
implementation 'com.google.firebase:firebase-core:17.2.1'
implementation "com.google.android.gms:play-services-gcm:16.0.0"
implementation "com.google.firebase:firebase-messaging:20.0.1"
implementation "com.google.firebase:firebase-analytics:17.2.1"
MainActivity.java
private FirebaseAnalytics mFirebaseAnalytics;
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, R.style.SplashScreenTheme); // here
super.onCreate(savedInstanceState);
// Obtain the FirebaseAnalytics instance.
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
}
原生反应
import firebase from "react-native-firebase";
firebase.analytics().logEvent("your_custom_event", {"custom_parm": "cp_value"});
但我在 android 工作室的 logcat 控制台上收到此错误:
E/ReactNativeJS: Error: You attempted to use a firebase module that's not installed on your Android project by calling firebase.analytics().
Ensure you have:
1) Installed the required Firebase Android SDK dependency 'com.google.firebase:firebase-analytics' in your 'android/app/build.gradle' file.
2) Imported the 'io.invertase.firebase.analytics.RNFirebaseAnalyticsPackage' module in your 'MainApplication.java' file.
3) Added the 'new RNFirebaseAnalyticsPackage()' line inside of the RN 'getPackages()' method list.
See http://invertase.link/android for full setup instructions.
在 React Native 控制台中我看到:
D8: Program type already present: android.support.v4.app.INotificationSideChannel$Stub$Proxy
解决方法:
我使用了错误的版本:
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation "com.google.firebase:firebase-messaging:17.5.0"
implementation "com.google.firebase:firebase-analytics:16.4.0"
=> mainAppliction.java
add these line
import io.invertase.firebase.messaging.RNFirebaseMessagingPackage; // <-- Add this line
and add package
packages.add(new RNFirebaseMessagingPackage());
implementation project(':clevertap-react-native')
implementation 'com.clevertap.android:clevertap-android-sdk:3.6.0'
implementation 'com.android.support:multidex:1.0.3'
implementation "com.google.firebase:firebase-messaging:18.0.0"
// 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"
我已经在我的 React Native 应用程序中安装了 firebase,我需要 firebase 分析模块。
app/build.gradle:
implementation 'com.google.firebase:firebase-core:17.2.1'
implementation "com.google.android.gms:play-services-gcm:16.0.0"
implementation "com.google.firebase:firebase-messaging:20.0.1"
implementation "com.google.firebase:firebase-analytics:17.2.1"
MainActivity.java
private FirebaseAnalytics mFirebaseAnalytics;
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, R.style.SplashScreenTheme); // here
super.onCreate(savedInstanceState);
// Obtain the FirebaseAnalytics instance.
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
}
原生反应
import firebase from "react-native-firebase";
firebase.analytics().logEvent("your_custom_event", {"custom_parm": "cp_value"});
但我在 android 工作室的 logcat 控制台上收到此错误:
E/ReactNativeJS: Error: You attempted to use a firebase module that's not installed on your Android project by calling firebase.analytics().
Ensure you have:
1) Installed the required Firebase Android SDK dependency 'com.google.firebase:firebase-analytics' in your 'android/app/build.gradle' file.
2) Imported the 'io.invertase.firebase.analytics.RNFirebaseAnalyticsPackage' module in your 'MainApplication.java' file.
3) Added the 'new RNFirebaseAnalyticsPackage()' line inside of the RN 'getPackages()' method list.
See http://invertase.link/android for full setup instructions.
在 React Native 控制台中我看到:
D8: Program type already present: android.support.v4.app.INotificationSideChannel$Stub$Proxy
解决方法: 我使用了错误的版本:
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation "com.google.firebase:firebase-messaging:17.5.0"
implementation "com.google.firebase:firebase-analytics:16.4.0"
=> mainAppliction.java
add these line
import io.invertase.firebase.messaging.RNFirebaseMessagingPackage; // <-- Add this line
and add package
packages.add(new RNFirebaseMessagingPackage());
implementation project(':clevertap-react-native')
implementation 'com.clevertap.android:clevertap-android-sdk:3.6.0'
implementation 'com.android.support:multidex:1.0.3'
implementation "com.google.firebase:firebase-messaging:18.0.0"
// 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"