如何在ReactNative中实现firebase分析 - Android

时间:2018-01-10 04:28:54

标签: android firebase react-native firebase-analytics

我有一个ReactNative应用程序。我正在尝试将firebase分析添加到其中。

它在iOS上工作得非常好,但是它给了我Android中的错误列表。

这是我的Build.gradle文件

apply plugin: "com.android.application"

    import com.android.build.OutputFile

    apply from: "../../node_modules/react-native/react.gradle"

    def enableSeparateBuildPerCPUArchitecture = false

    def enableProguardInReleaseBuilds = false

    android {
        signingConfigs {
            release {
                keyAlias ALIAS
                keyPassword PASSWORD
                storeFile file(PATH)
                storePassword SPASSWORD
            }
        }
        compileSdkVersion 25
        buildToolsVersion "25.0.3"
        defaultConfig {
            applicationId "com.example.app"
            minSdkVersion 16
            targetSdkVersion 22
            versionCode 16
            versionName "0.0.16"
            ndk {
                abiFilters "armeabi-v7a", "x86"
            }
            multiDexEnabled true
        }

        splits {
            abi {
                reset()
                enable enableSeparateBuildPerCPUArchitecture
                universalApk false  // If true, also generate a universal APK
                include "armeabi-v7a", "x86"
            }
        }
        buildTypes {
            release {
                minifyEnabled enableProguardInReleaseBuilds
                proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
                signingConfig signingConfigs.release
            }
        }
        // applicationVariants are e.g. debug, release
        applicationVariants.all { variant ->
            variant.outputs.each { output ->
                // For each separate APK per architecture, set a unique version code as described here:
                // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
                def versionCodes = ["armeabi-v7a": 1, "x86": 2]
                def abi = output.getFilter(OutputFile.ABI)
                if (abi != null) {  // null for the universal-debug, universal-release variants
                    output.versionCodeOverride =
                            versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
                }
            }
        }
    }

    dependencies {

        compile project(':react-native-progresshub')
        compile project(':react-native-background-task')
        compile project(':react-native-fcm')
        //compile 'com.google.firebase:firebase-core:10.0.1'
        compile project(':react-native-image-picker')
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile 'com.android.support:appcompat-v7:25.3.1'
        compile 'com.facebook.react:react-native:+'
        // From node_modules
        compile project(':react-native-fabric')

        compile ("com.google.firebase:firebase-core:10.0.1"){
            //exclude group: 'com.google.android.gms'
        }
        compile(project(':react-native-firebase')) {
            exclude group: 'com.google.android.gms'
            transitive = false
        }

        compile ("com.google.firebase:firebase-analytics:10.0.1"){
            exclude group: 'com.google.android.gms'
        }
        compile ("com.google.firebase:firebase-auth:10.0.1"){
            exclude group: 'com.google.android.gms'
        }
        compile 'com.android.support:multidex:1.0.1'

    }


    buildscript {
        repositories {
            maven { url 'https://maven.fabric.io/public' }
        }
        dependencies {
            // The Fabric Gradle plugin uses an open ended version to react
            // quickly to Android tooling updates
            classpath 'io.fabric.tools:gradle:1.+'
        }
    }
    apply plugin: 'io.fabric'
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    // Run this once to be able to run the application with BUCK
    // puts all compile dependencies into folder libs for BUCK to use
    task copyDownloadableDepsToLibs(type: Copy) {
        from configurations.compile
        into 'libs'
    }


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

这是我的MainApplication.java

package com.kinektsiteapp;

import android.app.Application;

import com.facebook.react.ReactApplication;
import io.invertase.firebase.RNFirebasePackage;
import com.smixx.fabric.FabricPackage;
import com.amsoft.RNProgressHUB.RNProgressHUBPackage;
import com.evernote.android.job.JobManager;
//import com.barefootcoders.android.react.KDSocialShare.KDSocialShare;
import com.jamesisaac.rnbackgroundtask.BackgroundTaskPackage;
import com.evollu.react.fcm.FIRMessagingPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.crashlytics.android.Crashlytics;
import io.fabric.sdk.android.Fabric;

import java.util.Arrays;
import java.util.List;

import io.invertase.firebase.analytics.RNFirebaseAnalyticsPackage;
import io.invertase.firebase.auth.RNFirebaseAuthPackage;

public class MainApplication extends Application implements ReactApplication {


  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {

    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
              new MainReactPackage(),
              new RNFirebasePackage(),
              new FabricPackage(),
              new RNProgressHUBPackage(),
              new BackgroundTaskPackage(),
              new FIRMessagingPackage(),
              new RNFirebaseAnalyticsPackage(),
              new RNFirebaseAuthPackage()
      );
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
    Fabric.with(this, new Crashlytics());
  }
}

我正在低于错误。

  

E / AndroidRuntime:致命异常:Thread-12

     

处理:com.example.app,PID:9424

     

java.lang.NoClassDefFoundError:解析失败:Lcom / google / android / gms / internal / zzbql;

我无法理解哪些版本的库存在冲突。

我有RN0.44。

该应用在删除firebase模块并且只保留我们用于通知的fcm模块后效果很好。

0 个答案:

没有答案