question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React Native - checkDebugDuplicateClasses error on Android

See original GitHub issue

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Analytics, Push Notifications

Amplify Categories

analytics, notifications

Environment information

# Put output below this line
System:
    OS: macOS 11.3.1
    CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
    Memory: 50.54 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 15.0.1 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.0.3 - /usr/local/bin/npm
  Browsers:
    Chrome: 90.0.4430.212
    Safari: 14.1
  npmPackages:
    @aws-amplify/core: ^3.4.2 => 3.8.24 (4.0.3)
    @aws-amplify/pushnotification: ^4.0.3 => 4.0.3 
    @babel/core: ^7.9.6 => 7.14.3 
    @babel/preset-env: ^7.11.0 => 7.14.4 
    @babel/runtime: ^7.9.2 => 7.14.0 
    @nartc/react-native-barcode-mask: ^1.2.0 => 1.2.0 
    @react-native-async-storage/async-storage: ^1.15.5 => 1.15.5 
    @react-native-community/async-storage: ^1.12.1 => 1.12.1 
    @react-native-community/checkbox: ^0.5.5 => 0.5.8 
    @react-native-community/eslint-config: ^1.1.0 => 1.1.0 
    @react-native-community/masked-view: ^0.1.10 => 0.1.11 
    @react-native-community/netinfo: ^5.9.5 => 5.9.10 
    @react-native-community/push-notification-ios: ^1.5.0 => 1.8.0 (1.0.3)
    @react-native-community/toolbar-android: ^0.1.0-rc.2 => 0.1.0-rc.2 
    @react-navigation/bottom-tabs: ^5.5.2 => 5.11.11 
    @react-navigation/native: ^5.1.7 => 5.9.4 
    @react-navigation/stack: ^5.2.14 => 5.14.5 
    @sentry/react-native: ^2.3.0 => 2.4.3 
    HelloWorld:  0.0.1 
    amazon-cognito-identity-js: ^4.3.3 => 4.6.3 
    aws-amplify: ^3.3.2 => 3.4.3 
    aws-amplify-react-native: ^4.2.1 => 4.3.3 
    axios: ^0.20.0 => 0.20.0 (0.21.1)
    babel-eslint: ^10.1.0 => 10.1.0 
    babel-jest: ^25.5.1 => 25.5.1 
    babel-plugin-transform-remove-console: ^6.9.4 => 6.9.4 
    eslint: ^6.8.0 => 6.8.0 
    eslint-plugin-react: ^7.19.0 => 7.24.0 (7.19.0)
    eslint-plugin-react-native: ^3.8.1 => 3.11.0 (3.8.1)
    hermes-inspector-msggen:  1.0.0 
    husky: ^0.13.4 => 0.13.4 
    jest: ^25.5.4 => 25.5.4 
    lodash: ^4.17.20 => 4.17.21 
    metro-react-native-babel-preset: ^0.59.0 => 0.59.0 
    moment: ^2.29.1 => 2.29.1 
    native-base: ^2.13.12 => 2.15.2 
    react: 16.11.0 => 16.11.0 
    react-animated:  0.1.0 
    react-native: ^0.63.2 => 0.63.4 
    react-native-app-intro-slider: ^4.0.4 => 4.0.4 
    react-native-autocomplete-input: ^4.1.0 => 4.2.0 
    react-native-camera: ^3.23.1 => 3.44.0 
    react-native-circle-slider: ^2.7.0 => 2.9.0 
    react-native-collapsible: ^1.6.0 => 1.6.0 
    react-native-date-picker: ^3.2.3 => 3.3.1 
    react-native-dialog-input: ^1.0.8 => 1.0.8 
    react-native-dropdown-picker: ^3.0.4 => 3.8.3 
    react-native-elements: ^2.0.2 => 2.3.2 
    react-native-geolocation-service: ^5.0.0 => 5.2.0 
    react-native-gesture-handler: ^1.9.0 => 1.10.3 
    react-native-image-base64: ^0.1.4 => 0.1.4 
    react-native-image-resizer: ^1.4.2 => 1.4.4 
    react-native-interactable: ^2.0.1 => 2.0.1 
    react-native-keychain: ^6.0.0 => 6.2.0 
    react-native-languages: ^3.0.2 => 3.0.2 
    react-native-localization: ^2.1.6 => 2.1.7 
    react-native-localize: ^1.4.0 => 1.4.3 
    react-native-modal: ^11.5.6 => 11.10.0 
    react-native-popup-menu: ^0.15.9 => 0.15.10 
    react-native-reanimated: ^1.8.0 => 1.13.3 
    react-native-safe-area-context: ^3.1.9 => 3.2.0 
    react-native-screens: ^2.7.0 => 2.18.1 
    react-native-side-menu-updated: ^1.3.2 => 1.3.2 
    react-native-snap-carousel: ^3.9.1 => 3.9.1 
    react-native-splash-screen: ^3.2.0 => 3.2.0 
    react-native-svg: ^12.1.0 => 12.1.1 
    react-native-text-ticker: ^1.12.0 => 1.12.0 
    react-native-user-avatar: ^1.0.7 => 1.0.7 
    react-native-vector-icons: ^6.6.0 => 6.7.0 (7.1.0)
    react-native-version-info: ^1.1.0 => 1.1.0 
    react-native-webview: ^10.7.0 => 10.10.2 
    react-redux: ^7.2.0 => 7.2.4 
    react-test-renderer: 16.11.0 => 16.11.0 
    redux: ^4.0.5 => 4.1.0 
    redux-actions: ^2.6.5 => 2.6.5 
    redux-devtools-extension: ^2.13.8 => 2.13.9 
    redux-persist: ^6.0.0 => 6.0.0 
    redux-persist/integration/react:  undefined ()
    redux-promise: ^0.6.0 => 0.6.0 
    redux-thunk: ^2.3.0 => 2.3.0 
    victory-native: ^35.0.0 => 35.3.3 
  npmGlobalPackages:
    @aws-amplify/cli: 4.32.0
    npm: 7.0.3
    react-native-cli: 2.0.1
    serverless: 2.10.0


Describe the bug

I am trying to get amplify push notifications running on Android with React Native. Since I have integrated the package @aws-amplify/pushnotification, I can not get my Android app to build and run any more. The error message is:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> 1 exception was raised by workers:
  java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class com.google.android.gms.gcm.PendingCallback found in modules jetified-firebase-jobdispatcher-0.6.0-runtime.jar (com.firebase:firebase-jobdispatcher:0.6.0) and jetified-play-services-gcm-16.1.0-runtime.jar (com.google.android.gms:play-services-gcm:16.1.0)
  Duplicate class com.google.android.gms.internal.measurement.zzu found in modules jetified-firebase-analytics-impl-16.2.4-runtime.jar (com.google.firebase:firebase-analytics-impl:16.2.4) and jetified-play-services-measurement-19.0.0-runtime.jar (com.google.android.gms:play-services-measurement:19.0.0)
  Duplicate class com.google.android.gms.internal.measurement.zzv found in modules jetified-firebase-analytics-impl-16.2.4-runtime.jar (com.google.firebase:firebase-analytics-impl:16.2.4) and jetified-play-services-measurement-19.0.0-runtime.jar (com.google.android.gms:play-services-measurement:19.0.0)
  Duplicate class com.google.android.gms.internal.measurement.zzw found in modules jetified-firebase-analytics-impl-16.2.4-runtime.jar (com.google.firebase:firebase-analytics-impl:16.2.4) and jetified-play-services-measurement-19.0.0-runtime.jar (com.google.android.gms:play-services-measurement:19.0.0)
  Duplicate class com.google.android.gms.measurement.AppMeasurement found in modules jetified-firebase-analytics-impl-16.2.4-runtime.jar (com.google.firebase:firebase-analytics-impl:16.2.4) and jetified-play-services-measurement-impl-19.0.0-runtime.jar (com.google.android.gms:play-services-measurement-impl:19.0.0)
...

There had been already a bug filed for this bug it had been closed without a resolution to the problem just because of inactivity: https://github.com/aws-amplify/amplify-js/issues/4593

Expected behavior

I can build and run my Android app as usual

Reproduction steps

  1. Follow the instructions https://docs.amplify.aws/lib/push-notifications/getting-started/q/platform/js for setting push notifications up on Android (alternatively also follow this guide for instructions about integrating it for React Native > 0.60 https://medium.com/@dantasfiles/setting-up-android-push-notifications-with-aws-amplify-e6334c6356d8)

Code Snippet

Just follow the guide https://medium.com/@dantasfiles/setting-up-android-push-notifications-with-aws-amplify-e6334c6356d8

Log output

I don’t even get the app to run, so not debug output possible

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

Android

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
the-smart-home-makercommented, Jun 4, 2021

Hi @chrisbonifacio,

Even further information - here’s my android/app/build.gradle:

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    enableHermes: true,  // clean and rebuild if changing
]

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

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

/**
 * The preferred build flavor of JavaScriptCore.
 *
 * 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-intl:+'

/**
 * Whether to enable the Hermes VM.
 *
 * This should be set on project.ext.react and mirrored here.  If it is not set
 * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
 * and the benefits of using Hermes will therefore be sharply reduced.
 */
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 {
        applicationId ...
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode ...
        versionName ...
	missingDimensionStrategy 'react-native-camera', 'general'
	manifestPlaceholders = [
      		appAuthRedirectScheme: ...
	]
        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'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
	        minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro", "devsupport.pro"
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://facebook.github.io/react-native/docs/signed-apk-android.
            signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }

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

    // 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
            }

        }
    }
}

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

    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

    // Import the BoM for the Firebase platform
    implementation platform('com.google.firebase:firebase-bom:28.0.1')

    // Declare the dependencies for the Firebase Cloud Messaging and Analytics libraries
    // When using the BoM, you don't specify versions in Firebase library dependencies
    implementation 'com.google.firebase:firebase-messaging' 
    implementation 'com.google.firebase:firebase-analytics'

    implementation "com.google.android.gms:play-services-gcm:17.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'
    }

    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }

     implementation(project(':aws-amplify_pushnotification'), {}) 

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

    // Multidex
    implementation 'com.android.support:multidex:1.0.3'

    configurations.all {
        resolutionStrategy {
            force 'com.google.android.gms:play-services-gcm:16.1.0'
            force 'com.google.android.gms:play-services-base:16.1.0'
            force 'com.google.firebase:firebase-core:16.0.6'
            force 'com.google.firebase:firebase-messaging:17.6.0'
        }
    }

}

// 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)

apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

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

where ... are anonymizations.

Also I have created a dependency tree for maybe more information about the dependencies for com.firebase:firebase-jobdispatcher and com.google.android.gms:play-services-gcm (just picked the compilation variant for debug exemplarily):

...
debugCompileClasspath - Resolved configuration for compilation for variant: debug
...
+--- com.google.android.gms:play-services-gcm:17.0.0 -> 16.1.0
...
+--- project :aws-amplify_pushnotification
...
|    \--- com.firebase:firebase-jobdispatcher:0.6.0
...
+--- com.google.android.gms:play-services-gcm:{strictly 16.1.0} -> 16.1.0 (c)
...
+--- com.firebase:firebase-jobdispatcher:{strictly 0.6.0} -> 0.6.0 (c)

Maybe that helps as well?

1reaction
the-smart-home-makercommented, Jun 4, 2021

Hey @chrisbonifacio,

Thanks for investigating! One more important information- on iOS, everything runs smoothly and I can get push notifications delivered as expected. It’s just on Android that I experience problems.

Thank you and best regards The Smart Home Maker

Read more comments on GitHub >

github_iconTop Results From Across the Web

React native build failed Execution failed for task ':app ...
iam new to react native tried to integrate payumobile for payment integradtion recieves error Execution failed for task ':app: ...
Read more >
Task :app:checkDebugDuplicateClasses FAILED · Issue #1383
Description: Hi. I have installed react-native-onesignal and after running npm run android I get error Task :app:checkDebugDuplicateClasses ...
Read more >
app:packagerelease react-native, execution failed for task
Solution of Execution failed for task processDebugResources Android Error in React Native: 1. Open your react native project folder in CMD (Command Prompt)...
Read more >
Android Native Modules
Android studio is an IDE built for Android development and using it will help you resolve minor issues like code syntax errors quickly....
Read more >
Execution failed for task ':app:checkDebugDuplicateClasses'
الله يسعدكم وصلوا على النبي واشتراك في القناة FAILURE : Build ... A failure occurred while executing com. android.build.gradle.internal.tasks.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found