1

I have an ReactNative App. I am trying to add firebase analytics into it.

It is working very well for iOS but it is giving me list of errors in Android.

This is my Build.gradle file

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'

This is my 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());
  }
}

And I am getting below Error.

E/AndroidRuntime: FATAL EXCEPTION: Thread-12

Process: com.example.app, PID: 9424

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/internal/zzbql;

I am not able to understand what version of libraries are conflicting.

I have RN0.44.

The app works well after removing firebase modules and only keeping fcm modules which we have used for notifications.

Community
  • 1
  • 1
BeingExpert
  • 523
  • 1
  • 5
  • 16

0 Answers0