Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ailtonaires opened this issue May 7, 2024 · 7 comments
Closed
Labels
Help: Needs Triage Issue needs additional investigation/triaging. Impact: Bug New bug report

Comments

@ailtonaires
Copy link

ailtonaires commented May 7, 2024

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)

`

`

<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:

{
  "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"
  }
}
@ailtonaires ailtonaires added Help: Needs Triage Issue needs additional investigation/triaging. Impact: Bug New bug report labels May 7, 2024
@ailtonaires ailtonaires changed the title [馃悰] [馃悰] [ANDROID] Duplicate class com.google.firebase.Timestamp May 8, 2024
@sridixteam
Copy link

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

@Doipah
Copy link

Doipah commented May 8, 2024

facing same issue..

@sridixteam
Copy link

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

/**

  • This is the configuration block to customize your React Native Android app.

  • By default you don't need to apply any configuration, just uncomment the lines you need.
    */
    react {
    ...........

    // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
    // hermesFlags = ["-O", "-output-source-map"]
    }

/**

  • Set this to true to create four separate APKs instead of one,
  • one for each native architecture. This is useful if you don't
  • use App Bundles (https://developer.android.com/guide/app-bundle/)
  • and want to have separate APKs to upload to the Play Store.
    */
    def enableSeparateBuildPerCPUArchitecture = false

/**

  • Set this to true to Run Proguard on Release builds to minify the Java bytecode.
    */
    def enableProguardInReleaseBuilds = false

/**

  • The preferred build flavor of JavaScriptCore (JSC)
  • For example, to use the international variant, you can use:
  • def jscFlavor = 'org.webkit:android-jsc-intl:+'
  • The international variant includes ICU i18n library and necessary data
  • allowing to use e.g. Date.toLocaleString and String.localeCompare that
  • give correct results when using with locales other than en-US. Note that
  • this variant is about 6MiB larger per architecture than default.
    */
    def jscFlavor = 'org.webkit:android-jsc:+'

/**

  • Private function to get the list of Native Architectures you want to build.
  • This reads the value from reactNativeArchitectures in your gradle.properties
  • file and works together with the --active-arch-only flag of react-native run-android.
    */
    def reactNativeArchitectures() {
    def value = project.getProperties().get("reactNativeArchitectures")
    return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
    }

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
Copy link

Doipah commented May 8, 2024

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

@mikehardy
Copy link
Collaborator

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
Copy link
Author

ailtonaires commented May 10, 2024

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

I removed the line below and it worked for me:

//firebaseMessagingVersion = "+"

@mikehardy
Copy link
Collaborator

react-native-firebase expects to define and control the versions of your firebase-android-sdk dependencies

If you add direct dependencies entries in your gradle files for firebase, then you must expect to take on the work of making sure they are the correct versions and kept correct over time relative to the firebase-android-sdk dependencies

If you do not do that, then you'll attempt to build with multiple versions of the same firebase-android-sdk dependencies and of course that will lead to build problems

That is not something we can help with - we expect you to use autolinking as is built in to react-native and to let react-native-firebase handle all the firebase-android-sdk dependencies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help: Needs Triage Issue needs additional investigation/triaging. Impact: Bug New bug report
Projects
None yet
Development

No branches or pull requests

4 participants