React-native-camera: Error build when change to mlkit

Created on 9 Feb 2021  路  1Comment  路  Source: react-native-camera/react-native-camera

Bug Report

To Do First

  • [x] Did you try latest release?
  • [x] Did you try master?
  • [x] Did you look for existing matching issues?

Platforms



i test only android

Versions

Description/Current Behaviour

Transform artifact firebase-ml-vision-face-model-17.0.2.aar (com.google.firebase:firebase-ml-vision-face-model:17.0.2) with DexingWithClasspathTransform

> Task :app:checkDebugDuplicateClasses FAILED

AGPBI: {"kind":"error","text":"Type com.google.android.gms.internal.vision.zzhh is referenced as an interface from `com.google.android.gms.internal.vision.zzjx$zza$zza`.","sources":[{}],"tool":"D8"}

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.internal.vision.zzbl found in modules jetified-firebase-ml-vision-face-model-17.0.2-runtime.jar (com.google.firebase:firebase-ml-vision-face-model:17.0.2) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzbm found in modules jetified-firebase-ml-vision-face-model-17.0.2-runtime.jar (com.google.firebase:firebase-ml-vision-face-model:17.0.2) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzbn found in modules jetified-firebase-ml-vision-face-model-17.0.2-runtime.jar (com.google.firebase:firebase-ml-vision-face-model:17.0.2) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzbo found in modules jetified-firebase-ml-vision-face-model-17.0.2-runtime.jar (com.google.firebase:firebase-ml-vision-face-model:17.0.2) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzbp found in modules jetified-firebase-ml-vision-face-model-17.0.2-runtime.jar (com.google.firebase:firebase-ml-vision-face-model:17.0.2) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzbr found in modules jetified-firebase-ml-vision-face-model-17.0.2-runtime.jar (com.google.firebase:firebase-ml-vision-face-model:17.0.2) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zze found in modules play-services-vision-20.0.0-runtime.jar (com.google.android.gms:play-services-vision:20.0.0) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzf found in modules play-services-vision-20.0.0-runtime.jar (com.google.android.gms:play-services-vision:20.0.0) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzg found in modules play-services-vision-20.0.0-runtime.jar (com.google.android.gms:play-services-vision:20.0.0) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzh found in modules play-services-vision-20.0.0-runtime.jar (com.google.android.gms:play-services-vision:20.0.0) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzi found in modules play-services-vision-20.0.0-runtime.jar (com.google.android.gms:play-services-vision:20.0.0) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzjx found in modules jetified-firebase-ml-vision-face-model-17.0.2-runtime.jar (com.google.firebase:firebase-ml-vision-face-model:17.0.2) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzjy found in modules jetified-firebase-ml-vision-face-model-17.0.2-runtime.jar (com.google.firebase:firebase-ml-vision-face-model:17.0.2) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzjz found in modules jetified-firebase-ml-vision-face-model-17.0.2-runtime.jar (com.google.firebase:firebase-ml-vision-face-model:17.0.2) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzka found in modules jetified-firebase-ml-vision-face-model-17.0.2-runtime.jar (com.google.firebase:firebase-ml-vision-face-model:17.0.2) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzkb found in modules jetified-firebase-ml-vision-face-model-17.0.2-runtime.jar (com.google.firebase:firebase-ml-vision-face-model:17.0.2) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzkc found in modules jetified-firebase-ml-vision-face-model-17.0.2-runtime.jar (com.google.firebase:firebase-ml-vision-face-model:17.0.2) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzkd found in modules jetified-firebase-ml-vision-face-model-17.0.2-runtime.jar (com.google.firebase:firebase-ml-vision-face-model:17.0.2) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzke found in modules jetified-firebase-ml-vision-face-model-17.0.2-runtime.jar (com.google.firebase:firebase-ml-vision-face-model:17.0.2) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzkf found in modules jetified-firebase-ml-vision-face-model-17.0.2-runtime.jar (com.google.firebase:firebase-ml-vision-face-model:17.0.2) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzkg found in modules jetified-firebase-ml-vision-face-model-17.0.2-runtime.jar (com.google.firebase:firebase-ml-vision-face-model:17.0.2) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzv found in modules play-services-vision-20.0.0-runtime.jar (com.google.android.gms:play-services-vision:20.0.0) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
  Duplicate class com.google.android.gms.internal.vision.zzw found in modules play-services-vision-20.0.0-runtime.jar (com.google.android.gms:play-services-vision:20.0.0) and play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)

  Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 20s

Additionals
package.json

{
  "name": "rodney",
  "version": "0.0.1",
  "private": true,
  "main": "index.js",
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint . --ext .js,.jsx,.ts,.tsx"
  },
  "dependencies": {
    "@react-native-community/masked-view": "^0.1.10",
    "@react-navigation/native": "^5.9.2",
    "@types/json5": "^0.0.30",
    "@types/react-native-elements": "^0.18.0",
    "@unform/core": "^2.1.3",
    "@unform/mobile": "^2.1.3",
    "axios": "^0.21.1",
    "color": "^3.1.3",
    "expo-status-bar": "^1.0.3",
    "json5": "^2.1.3",
    "lottie-react-native": "^3.5.0",
    "native-base": "^2.15.0",
    "react": "16.13.1",
    "react-dom": "^16.13.1",
    "react-is": "^16.13.1",
    "react-native": "0.63.4",
    "react-native-camera": "git+https://[email protected]/react-native-community/react-native-camera.git",
    "react-native-device-info": "^8.0.1",
    "react-native-elements": "^3.1.0",
    "react-native-gesture-handler": "^1.9.0",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-paper": "^4.7.1",
    "react-native-reanimated": "^1.13.2",
    "react-native-rodney-broadcast": "^0.4.0",
    "react-native-safe-area-context": "^3.1.9",
    "react-native-screens": "^2.17.1",
    "react-native-svg": "^12.1.0",
    "react-native-vector-icons": "^8.0.0",
    "styled-components": "^5.2.1",
    "yup": "^0.32.8"
  },
  "devDependencies": {
    "@babel/core": "^7.8.4",
    "@babel/runtime": "^7.8.4",
    "@react-native-community/eslint-config": "^1.1.0",
    "@testing-library/jest-native": "^3.4.3",
    "@testing-library/react-hooks": "^5.0.3",
    "@testing-library/react-native": "^7.1.0",
    "@types/color": "^3.0.1",
    "@types/jest": "^25.2.3",
    "@types/react-native": "^0.63.2",
    "@types/react-native-vector-icons": "^6.4.6",
    "@types/react-test-renderer": "^16.9.2",
    "@types/styled-components": "^5.1.7",
    "@types/styled-components-react-native": "^5.1.1",
    "@types/yup": "^0.29.11",
    "@typescript-eslint/eslint-plugin": "^2.27.0",
    "@typescript-eslint/parser": "^2.27.0",
    "babel-jest": "^25.1.0",
    "eslint": "^6.5.1",
    "eslint-config-airbnb": "^18.2.1",
    "eslint-config-prettier": "^6.15.0",
    "eslint-import-resolver-typescript": "^2.3.0",
    "eslint-plugin-import": "^2.22.1",
    "eslint-plugin-jsx-a11y": "^6.4.1",
    "eslint-plugin-prettier": "^3.3.0",
    "eslint-plugin-react": "^7.21.5",
    "eslint-plugin-react-hooks": "^4.2.0",
    "eslint-plugin-styled-components-a11y": "^0.0.28",
    "jest": "^25.1.0",
    "metro-config": "^0.65.0",
    "metro-react-native-babel-preset": "^0.59.0",
    "prettier": "^2.1.2",
    "react-native-svg-transformer": "^0.14.3",
    "react-test-renderer": "16.13.1",
    "typescript": "^3.8.3"
  },
  "jest": {
    "preset": "react-native",
    "setupFilesAfterEnv": [
      "@testing-library/jest-native/extend-expect"
    ],
    "collectCoverageFrom": [
      "src/pages/**/*.tsx",
      "src/components/**/*.tsx",
      "src/hooks/*.tsx",
      "!src/hooks/index.tsx"
    ],
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js",
      "jsx",
      "json",
      "node"
    ],
    "setupFiles": [
      "./setupTests.ts",
      "./node_modules/react-native-gesture-handler/jestSetup.js"
    ],
    "transformIgnorePatterns": [
      "node_modules/(?!(jest-)?react-native|react-clone-referenced-element|@react-native-community|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|sentry-expo|@sentry/.*|react-native-svg|@codler|react-native-screens)",
      "screens/.*"
    ]
  }
}

build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
  ext {
    supportLibVersion = '1.0.2' // Use '28.0.0' or don't specify for old libraries, '1.0.2' or similar for AndroidX
    mediaCompatVersion = '1.0.1'
    // Do not specify if using old libraries, specify '1.0.1' or similar for androidx.media:media dependency
    supportV4Version = '1.0.0'
    // Do not specify if using old libraries, specify '1.0.0' or similar for androidx.legacy:legacy-support-v4 dependency
    firebaseIidVersion = "19.0.1"
    buildToolsVersion = "29.0.2"
    minSdkVersion = 16
    compileSdkVersion = 29
    targetSdkVersion = 29
  }
  repositories {
    google()
    jcenter()
  }
  dependencies {
    classpath("com.android.tools.build:gradle:3.5.3")
    classpath 'com.google.gms:google-services:4.3.5'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
  }
}

allprojects {
  repositories {
    google()
    mavenLocal()
    maven {
      // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
      url("$rootDir/../node_modules/react-native/android")
    }
    maven {
      // Android JSC is installed from npm
      url("$rootDir/../node_modules/jsc-android/dist")
    }
    jcenter()
    maven { url 'https://www.jitpack.io' }
  }
}

apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'

import com.android.build.OutputFile

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

apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-vector-icons/fonts.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 {
    applicationId "com.rodney"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    missingDimensionStrategy 'react-native-camera', 'mlkit'
  }
  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 {
      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"
    }
  }

  // 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 project(':react-native-camera')
  implementation fileTree(dir: "libs", include: ["*.jar"])
  //noinspection GradleDynamicVersion
  implementation "com.facebook.react:react-native:+"  // From node_modules

  implementation 'androidx.multidex:multidex:2.0.1'

  implementation platform('com.google.firebase:firebase-bom:26.4.0')
  implementation 'com.google.firebase:firebase-analytics'

  implementation 'org.conscrypt:conscrypt-android:2.2.1'

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

  implementation(project(':react-native-device-info')) {
    exclude group: 'com.google.android.gms'
  }

  if (enableHermes) {
    def hermesPath = "../../node_modules/hermes-engine/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)

Most helpful comment

Hi, this helped me. I've pasted it and haven't had the duplicate class error anymore

>All comments

Hi, this helped me. I've pasted it and haven't had the duplicate class error anymore

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alameddinc picture alameddinc  路  3Comments

TylerKirby picture TylerKirby  路  3Comments

shanematte picture shanematte  路  3Comments

weironghuang31 picture weironghuang31  路  3Comments

rmnrajan picture rmnrajan  路  3Comments