invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.45k stars 2.18k forks source link

[🐛] [ANDROID] Duplicate class com.google.firebase.Timestamp #7781

Open ailtonaires opened 1 week ago

ailtonaires commented 1 week ago

Issue

When trying to compile the application on Android, I am receiving the following error:

Execution failed for task ':app:checkDebugDuplicateClasses'.

A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
Duplicate class com.google.firebase.Timestamp found in modules jetified-firebase-common-21.0.0-runtime (com.google.firebase:firebase-common:21.0.0) and jetified-firebase-firestore-24.10.3-runtime (com.google.firebase:firebase-firestore:24.10.3)

The problem appears to be a duplication of classes between versions of firebase-common and firebase-firestore.


Project Files

buildscript {
    ext {

    //Added by ATENA for push
    googlePlayServicesVersion = "+"
    firebaseMessagingVersion = "+"

        buildToolsVersion = "33.0.2"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33
        supportLibVersion = "29.0.0"
    }
    repositories {
        mavenCentral()
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.2.2")
        classpath ('com.google.gms:google-services:4.3.3')
        // implementation 'com.facebook.soloader:soloader:0.10.4'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }

        // ADD THIS
        maven { url 'https://maven.google.com' }

        // ADD THIS
        maven { url "https://www.jitpack.io" }

        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }
        maven { url 'https://jitpack.io' }
        google()
        jcenter()
    }

    configurations.all {
        resolutionStrategy {
            force 'com.facebook.react:react-native:0.63.2'
        }
    }
}
apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'
import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js",
    enableHermes: false,  // clean and rebuild if changing
]

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

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

def jscFlavor = 'org.webkit:android-jsc:+'

def enableHermes = project.ext.react.get("enableHermes", false);

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

     packagingOptions {
        pickFirst 'lib/x86/libc++_shared.so'
        pickFirst 'lib/x86_64/libc++_shared.so'
        pickFirst 'lib/armeabi-v7a/libc++_shared.so'
        pickFirst 'lib/arm64-v8a/libc++_shared.so'
    }

    defaultConfig {
        applicationId "com.groovoo"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        missingDimensionStrategy 'react-native-camera', 'general'
        versionCode 251
        versionName "5.1.2"
        //Added by Atena
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
        release {
            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
                storeFile file(MYAPP_UPLOAD_STORE_FILE)
                storePassword MYAPP_UPLOAD_STORE_PASSWORD
                keyAlias MYAPP_UPLOAD_KEY_ALIAS
                keyPassword MYAPP_UPLOAD_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        debug {
            multiDexEnabled true //resolution https://github.com/facebook/react-native/issues/26484
            signingConfig signingConfigs.debug
        }
        release {
            multiDexEnabled true//resolution https://github.com/facebook/react-native/issues/26484
            // Caution! In production, you need to generate your own keystore file.
            // see https://facebook.github.io/react-native/docs/signed-apk-android.
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // 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:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
            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
            }

        }
    }

    packagingOptions {
        pickFirst '**/armeabi-v7a/libc++_shared.so'
        pickFirst '**/x86/libc++_shared.so'
        pickFirst '**/arm64-v8a/libc++_shared.so'
        pickFirst '**/x86_64/libc++_shared.so'
        pickFirst '**/x86/libjsc.so'
        pickFirst '**/armeabi-v7a/libjsc.so'
    }
}

dependencies {
    implementation project(':react-native-svg')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation "com.google.firebase:firebase-analytics:17.5.0"
    implementation "com.google.firebase:firebase-core:17.5.0"
    implementation(platform("com.google.firebase:firebase-bom:32.7.4"))
    implementation project(':react-native-vector-icons')

    //Added by Atena
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
    implementation 'com.facebook.soloader:soloader:0.10.4'

    if (enableHermes) {
      def hermesPath = "../../node_modules/hermesvm/android/";
      debugImplementation files(hermesPath + "hermes-debug.aar")
      releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
      implementation jscFlavor
    }
}

// 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 from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

`

`<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.groovoo">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
  <uses-permission android:name="android.permission.RECORD_AUDIO"/>
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<application
  android:requestLegacyExternalStorage="true"
  android:name=".MainApplication"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:roundIcon="@mipmap/ic_launcher_round"
  android:allowBackup="false"
  android:theme="@style/AppTheme"
  android:usesCleartextTraffic="true"
  >
  <meta-data 
    android:name="com.facebook.sdk.ApplicationId" 
    android:value="@string/facebook_app_id"
  />

  <!-- Change the value to true to enable pop-up for in foreground (remote-only, for local use ignoreInForeground) -->
  <meta-data  android:name="com.dieam.reactnativepushnotification.notification_foreground"
                android:value="false"/>
    <!-- Change the resource name to your App's accent color - or any other color you want -->
  <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
                android:resource="@android:color/white"/> <!-- or @android:color/{name} to use a standard color -->

  <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" />
  <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
  <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver" android:exported="true"> 
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
        </intent-filter>
  </receiver>

  <service
        android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
        android:exported="true" >
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
  </service>    

  <activity
    android:name=".MainActivity"
    android:exported="true"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:windowSoftInputMode="adjustResize">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter android:label="filter_react_native">
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
      <category android:name="android.intent.category.BROWSABLE" />
      <data android:scheme="groovooapp" android:host="post" />
    </intent-filter>
  </activity>
  <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>

`

I tried this, but it didn't work for me

https://stackoverflow.com/questions/78428458/how-to-fix-duplicate-class-com-google-firebase-timestamp/78438376#78438376

Click To Expand

#### `package.json`: ```json { "name": "Groovoo", "version": "99.0.0", "private": true, "scripts": { "start": "react-native start", "android": "react-native run-android", "test": "jest", "lint": "eslint ." }, "dependencies": { "@ethersproject/shims": "^5.7.0", "@invertase/react-native-apple-authentication": "^2.0.2", "@ptomasroos/react-native-multi-slider": "^1.0.0", "@react-native-community/async-storage": "^1.12.0", "@react-native-community/blur": "^4.3.2", "@react-native-community/datetimepicker": "^3.0.3", "@react-native-community/masked-view": "^0.1.10", "@react-native-community/netinfo": "^9.4.1", "@react-native-community/picker": "^1.8.0", "@react-native-community/push-notification-ios": "^1.5.0", "@react-native-community/toolbar-android": "^0.2.1", "@react-native-community/viewpager": "^4.1.6", "@react-native-firebase/analytics": "17.5.0", "@react-native-firebase/app": "17.5.0", "@react-native-firebase/auth": "17.5.0", "@react-native-firebase/firestore": "17.5.0", "@react-native-google-signin/google-signin": "^8.0.0", "@react-navigation/native": "^5.7.4", "@react-navigation/stack": "^5.9.1", "@xmpp/client": "^0.11.1", "@xmpp/debug": "^0.11.0", "aws-sdk": "^2.755.0", "axios": "^0.20.0", "base-64": "^0.1.0", "base64-arraybuffer": "^0.2.0", "create-react-class": "^15.6.3", "ethers": "^5.6.9", "fs": "0.0.1-security", "js-sha256": "^0.9.0", "jwt-decode": "^3.1.2", "lodash.filter": "^4.6.0", "lottie-react-native": "^3.3.2", "moment": "^2.27.0", "moment-timezone": "^0.5.33", "native-base": "^2.13.12", "otplib": "^12.0.1", "prop-types": "^15.7.2", "react": "16.13.1", "react-content-loader": "^5.1.4", "react-native": "0.63.2", "react-native-actionsheet": "^2.4.2", "react-native-autocomplete-input": "^4.2.0", "react-native-calendars": "^1.403.0", "react-native-camera": "^3.43.6", "react-native-circular-progress": "^1.3.6", "react-native-confirmation-code-field": "^6.5.0", "react-native-countdown-component": "^2.7.1", "react-native-country-picker-modal": "^2.0.0", "react-native-crypto-js": "^1.0.0", "react-native-datepicker": "^1.7.2", "react-native-device-info": "^3.1.4", "react-native-dotenv": "^2.6.2", "react-native-elements": "^3.4.2", "react-native-fast-image": "^7.0.2", "react-native-fbsdk": "^2.0.0", "react-native-fs": "^2.16.6", "react-native-gesture-handler": "^1.8.0", "react-native-get-random-values": "^1.8.0", "react-native-gifted-chat": "^0.10.1", "react-native-htmlview": "^0.17.0", "react-native-hyperlink": "0.0.22", "react-native-image-crop-picker": "^0.25.3", "react-native-linear-gradient": "^2.5.6", "react-native-modal-datetime-picker": "^9.0.0", "react-native-nfc-manager": "^3.13.5", "react-native-page-control": "^1.1.1", "react-native-phone-number-input": "^2.1.0", "react-native-picker-select": "^7.0.0-beta.0", "react-native-popup-dialog": "^0.18.3", "react-native-progress-wheel": "^1.0.5", "react-native-push-notification": "^7.3.0", "react-native-reanimated": "^1.2.0", "react-native-render-html": "^6.3.4", "react-native-safe-area-context": "^3.1.8", "react-native-screenguard": "^1.0.4-beta", "react-native-screens": "^2.11.0", "react-native-sideswipe": "^1.5.0", "react-native-svg": "^12.1.0", "react-native-vector-icons": "^7.1.0", "react-native-video": "^5.0.2", "react-native-view-overflow": "0.0.4", "react-navigation": "^3.13.0", "react-navigation-drawer": "^1.4.0", "react-navigation-stack": "^1.10.3", "react-navigation-tabs": "^1.2.0", "react-redux": "^7.1.1", "react-timer-mixin": "^0.13.4", "redux": "^4.0.4", "redux-thunk": "^2.3.0", "rn-tourguide": "^2.4.1", "semver": "^7.6.0", "string.prototype.replaceall": "^1.0.6", "uuid": "^8.3.1" }, "devDependencies": { "@babel/core": "^7.11.6", "@babel/runtime": "^7.11.2", "@react-native-community/eslint-config": "^2.0.0", "babel-jest": "^26.3.0", "eslint": "^7.9.0", "jest": "^26.4.2", "metro-react-native-babel-preset": "^0.63.0", "react-test-renderer": "16.13.1" }, "jest": { "preset": "react-native" } } ```

sridixteam commented 1 week ago

facing same issue.. did you find any solution @ailtonaires

Doipah commented 1 week ago

facing same issue..

sridixteam commented 1 week ago

just check your project level build.gradle file and remove extra thing which on is not used...

my android/build.gradle file souce code..........**

buildscript { ext { buildToolsVersion = "33.0.0" minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33 kotlinVersion = "1.8.0" // googlePlayServicesVersion = "+" // firebaseMessagingVersion = "+" // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP. ndkVersion = "23.1.7779620" } repositories { google() mavenCentral()

    maven { url 'https://maven.google.com' }
    maven { url "https://www.jitpack.io" }
}
dependencies {
    classpath("com.android.tools.build:gradle:7.3.1")
    classpath("com.facebook.react:react-native-gradle-plugin")
    classpath('com.google.gms:google-services:4.3.15')
}

}

and android/app/build.gradle file like this......***

apply plugin: "com.android.application" apply plugin: "com.facebook.react" apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" apply plugin: 'com.google.gms.google-services'

import com.android.build.OutputFile

/**

/**

/**

/**

/**

android { packagingOptions { pickFirst 'lib/x86/libc++_shared.so' pickFirst 'lib/x86_64/libjsc.so' pickFirst 'lib/arm64-v8a/libjsc.so' pickFirst 'lib/arm64-v8a/libc++_shared.so' pickFirst 'lib/x86_64/libc++_shared.so' pickFirst 'lib/armeabi-v7a/libc++_shared.so' } ndkVersion rootProject.ext.ndkVersion buildToolsVersion rootProject.ext.buildToolsVersion compileSdkVersion rootProject.ext.compileSdkVersion

namespace "YOUR_PACKAGE_NAME"
defaultConfig {
    applicationId "NAME"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 4
    versionName "1.3"
    vectorDrawables.useSupportLibrary = true
}

splits {
    abi {
        reset()
        enable enableSeparateBuildPerCPUArchitecture
        universalApk false  // If true, also generate a universal APK
        include (*reactNativeArchitectures())
    }
}
signingConfigs {
    debug {
        storeFile file('debug.keystore')
        storePassword 'android'
        keyAlias 'androiddebugkey'
        keyPassword 'android'
    }
}
buildTypes {
    debug {
        signingConfig signingConfigs.debug
    }
    release {
        // Caution! In production, you need to generate your own keystore file.
        // see https://reactnative.dev/docs/signed-apk-android.
        signingConfig signingConfigs.debug
        minifyEnabled enableProguardInReleaseBuilds
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    }
}
buildFeatures {
    viewBinding true
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

// 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:
        // https://developer.android.com/studio/build/configure-apk-splits.html
        // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
        def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
        def abi = output.getFilter(OutputFile.ABI)
        if (abi != null) {  // null for the universal-debug, universal-release variants
            output.versionCodeOverride =
                    defaultConfig.versionCode * 1000 + versionCodes.get(abi)
        }

    }
}

}

dependencies { // The version of react-native is set by the React Native Gradle Plugin implementation("com.facebook.react:react-android")

implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")
implementation("androidx.core:core-splashscreen:1.0.0")
implementation ('com.google.firebase:firebase-bom:32.7.2')

debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
    exclude group:'com.squareup.okhttp3', module:'okhttp'
}

debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
if (hermesEnabled.toBoolean()) {
    implementation("com.facebook.react:hermes-android")
} else {
    implementation jscFlavor
}

}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

Doipah commented 1 week ago

and android/app/build.gradle. remove :+ implementation "com.facebook.react:react-native:+" => implementation "com.facebook.react:react-native" work for me 🙏

mikehardy commented 1 week ago

There is no reason to have direct firebase dependencies in your app level build.gradle, and certainly not with outdated versions.

Auto linking will bring those dependencies in for you from the react-native-firebase modules.

If you must depend on them directly for some project-specific reason (like you have custom native code on Android that uses firebase native apis directly...), remove the bom one, just depend on the specific modules you need and do not specify a version

ailtonaires commented 1 week ago

facing same issue.. did you find any solution @ailtonaires

I removed the line below and it worked for me:

//firebaseMessagingVersion = "+"