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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android build issue: "Execution failed for task ':app:checkDebugDuplicateClasses'." #293

Open
sethcwhiting opened this issue Jun 30, 2022 · 7 comments

Comments

@sethcwhiting
Copy link

sethcwhiting commented Jun 30, 2022

I'm a JS/React/React Native dev who rarely needs to deal with native code and I'm struggling a bit to get my app running with this package installed. I followed each step of the installation instructions, and I was able to eventually get the project to build on iOS with a lot of help from a friend who's an iOS expert. I'm still struggling with the Android build, though. I'm getting this error:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class com.google.android.gms.internal.measurement.zzbm found in modules jetified-play-services-measurement-17.2.1-runtime (com.google.android.gms:play-services-measurement:17.2.1) and jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2)
     Duplicate class com.google.android.gms.internal.measurement.zzbn found in modules jetified-play-services-measurement-17.2.1-runtime (com.google.android.gms:play-services-measurement:17.2.1) and jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2)

{...a bunch more like this...}

     Duplicate class com.google.android.gms.measurement.internal.zzio found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-17.2.1-runtime (com.google.android.gms:play-services-measurement-impl:17.2.1)
     Duplicate class com.google.android.gms.measurement.internal.zzit found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-17.2.1-runtime (com.google.android.gms:play-services-measurement-impl:17.2.1)

It seems like there's probably a conflict with another package I'm using on the project, but I'm at a bit of a loss as to which one. Then once I find the conflicting package, I'm not really sure how to go about resolving the conflict. Any help/insight I could get on this would be greatly appreciated. For context, here's my android/app/build.gradle file:

apply plugin: "com.android.application"
apply plugin: 'ly.img.android.sdk'
apply plugin: 'kotlin-android'

imglyConfig {
    modules {
        include 'ui:text'
        include 'ui:focus'
        include 'ui:frame'
        include 'ui:brush'
        include 'ui:filter'
        include 'ui:sticker'
        include 'ui:overlay'
        include 'ui:transform'
        include 'ui:adjustment'
        include 'ui:text-design'
        include 'ui:video-trim'
        include 'ui:video-library'
        include 'ui:video-composition'
        include 'ui:audio-composition'
        include 'backend:serializer'
        include 'assets:font-basic'
        include 'assets:frame-basic'
        include 'assets:filter-basic'
        include 'assets:overlay-basic'
        include 'assets:sticker-shapes'
        include 'assets:sticker-emoticons'
        include 'backend:sticker-smart'
    }
}

import com.android.build.OutputFile

project.ext.react = [
    enableHermes: (findProperty('expo.jsEngine') ?: "jsc") == "hermes",
    cliPath: new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() + "/cli.js",
    hermesCommand: new File(["node", "--print", "require.resolve('hermes-engine/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() + "/%OS-BIN%/hermesc",
    composeSourceMapsPath: new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() + "/scripts/compose-source-maps.js",
]

apply from: new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim(), "../react.gradle")
apply from: new File(["node", "--print", "require.resolve('@sentry/react-native/package.json')"].execute().text.trim(), "../sentry.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
    }

    defaultConfig {
      missingDimensionStrategy 'react-native-camera', 'general'
        applicationId 'xxx.xxx.xxx'
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 6
        versionName "1.14.0"
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            
            
            
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }

    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"  

    def isGifEnabled = (findProperty('expo.gif.enabled') ?: "") == "true";
    def isWebpEnabled = (findProperty('expo.webp.enabled') ?: "") == "true";
    def isWebpAnimatedEnabled = (findProperty('expo.webp.animated') ?: "") == "true";

    if (isGifEnabled || isWebpEnabled) {
        implementation 'com.facebook.fresco:fresco:2.0.0'
        implementation 'com.facebook.fresco:imagepipeline-okhttp3:2.0.0'
    }

    if (isGifEnabled) {
        implementation 'com.facebook.fresco:animated-gif:2.0.0'
    }

    if (isWebpEnabled) {
        implementation 'com.facebook.fresco:webpsupport:2.0.0'
        if (isWebpAnimatedEnabled) {
            implementation 'com.facebook.fresco:animated-webp:2.0.0'
        }
    }
    
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
      exclude group:'com.facebook.fbjni'
    }
    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }
    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }

    if (enableHermes) {
        debugImplementation files(new File(["node", "--print", "require.resolve('hermes-engine/package.json')"].execute(null, rootDir).text.trim(), "../android/hermes-debug.aar"))
        releaseImplementation files(new File(["node", "--print", "require.resolve('hermes-engine/package.json')"].execute(null, rootDir).text.trim(), "../android/hermes-release.aar"))
    } else {
        implementation jscFlavor
    }
}



task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
applyNativeModulesAppBuildGradle(project)

apply plugin: 'com.google.gms.google-services'
    android {
      defaultConfig {
          multiDexEnabled true
      }
    }
    dependencies {
      implementation 'androidx.multidex:multidex:2.0.1'
    }
@sethcwhiting
Copy link
Author

I tried most of the solutions in this thread, and I was able to get it to the point where it built successfully, but then immediately crashed every time I opened the app. Also, in order to do that, I had to downgrade a few things. I was hoping to not have to do that, but if I need to in order for it to work, that's fine.

@aziradevs
Copy link

i have solved this issue by removing the all firebase dependencies and added only the dependency what the code needed.
i use Android Studio and it seems u use React Native so i hope logic are same for both

@jorgegvallejo
Copy link

Hey @sethcwhiting did you solve the crash on launch?

@sethcwhiting sethcwhiting reopened this Jul 13, 2022
@sethcwhiting
Copy link
Author

sethcwhiting commented Jul 13, 2022

Hey guys I’m reopening this now.
I ran ./gradlew app::dependencies in my android/ folder and found that expo-firebase-analytics was the culprit. I removed that package so that I could just work on AdMob stuff for a while, but now I’m at the point where I really need analytics back.

@ammarahm-ed do you or anyone else know of any way to reconcile the 2 packages? Maybe force react-native-admob-native-ads to use com.google.android.gms:play-services-measurement-sdk-api:17.2.1 or something?

Screen Shot 2022-07-13 at 3 42 54 PM

Screen Shot 2022-07-13 at 3 43 58 PM

@aziradevs
Copy link

Try Latest Firebase analytics dependency.

@sethcwhiting
Copy link
Author

sethcwhiting commented Jul 15, 2022

thanks, @emdotysru21, When I do that, I get a bunch of other errors on Android and my iOS build breaks.
It seems to me like the best way to go about this would be to reference com.google.android.gms:play-services-measurement:17.2.1 in react-native-admob-native-ads, but I'm not sure how to do that

@tsalama
Copy link

tsalama commented Sep 27, 2023

Facing this same issue. I'm unable to use this library alongside react-native-notifications's default firebase version: implementation 'com.google.firebase:firebase-core:16.0.0'.

I was able to get it working but I had to upgrade to implementation 'com.google.firebase:firebase-core:20.1.2' to match this library's but not sure if that'll introduce issues/regressions for notifications. Will update here if so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants