Note: I've written these notes while not having a lot of time to re-read and cleanup. Please keep this in mind. Also my app is named lc
When trying to build I run into this issue with duplicate class names. After doing some research I figured out that react-native-camera
was causing an include of firebase 16 and react-native-onesignal
was including version 18.
Execution failed for task ':app:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
> Duplicate class com.google.firebase.components.AbstractComponentContainer found in modules jetified-firebase-common-18.0.0-runtime (com.google.firebase:firebase-common:18.0.0) and jetified-firebase-components-16.1.0-runtime (com.google.firebase:firebase-components:16.1.0)
My directory tree is like:
$ cd <repository-name>
$ tree . -L 3
$ tree . -L 3
.
├── lc
│ ├── android
│ │ ├── app
│ │ ├── build
│ │ ├── build.gradle
│ │ ├── deps.txt
│ │ ├── gradle
│ │ ├── gradle.properties
│ │ ├── gradlew
│ │ ├── gradlew.bat
│ │ └── settings.gradle
│ ├── app
│ │ ├── assets
│ │ ├── core
│ │ ├── legacy
│ │ ├── locales
│ │ ├── navigation
│ │ ├── providers
│ │ ├── screens
│ │ ├── scripts
│ │ ├── selectors
│ │ ├── services
│ │ ├── styles
│ │ └── ui
│ ├── App.js
│ ├── app.json
│ ├── babel.config.js
│ ├── _editorconfig
│ ├── editorconfig
│ ├── index.js
│ ├── ios
│ │ ├── lc
│ │ ├── lcTests
│ │ ├── lc.xcodeproj
│ │ ├── lc.xcworkspace
│ │ ├── Podfile
│ │ └── Podfile.lock
│ ├── metro.config.js
│ ├── node_modules
│ │ ├── react-native-camera
│ │ ├── react-native-onesignal
...
│ ├── package.json
│ ├── react-native.config.js
│ ├── __tests__
│ │ └── App-test.js
│ └── yarn.lock
Gradle from react-native-camera:
This is what react-native-camera was including as dependency; notice that it tries to use com.google.android.gms
version 16.3.0. The solution as described at the bottom here, basically excludes this version.
dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
implementation "com.google.zxing:core:3.3.3"
implementation "com.drewnoakes:metadata-extractor:2.11.0"
implementation "androidx.exifinterface:exifinterface:1.3.2"
implementation "androidx.annotation:annotation:1.0.0"
implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation "com.google.android.gms:play-services-mlkit-text-recognition:16.3.0" /* <----*/
generalImplementation "com.google.android.gms:play-services-mlkit-barcode-scanning:16.2.0"
generalImplementation "com.google.android.gms:play-services-mlkit-face-detection:16.2.0"
mlkitImplementation "com.google.mlkit:barcode-scanning:16.2.0"
mlkitImplementation "com.google.mlkit:face-detection:16.1.2"
}
Gradle from react-native-onesignal
The docs from OneSignal says you have to add this to your lc/android/app/build.gradle
:
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10, 0.99.99]'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
Output of ./gradlew :app:dependencies
:
This output shows what libraries are used by which subproject. It shows that react-native-camera
uses version 16 of firebase and react-native-onesignal
version 18. I've included this info to make this clear. Also note that the libs were renamed.
...
+--- project :react-native-onesignal
| \--- com.onesignal:OneSignal:4.6.0
| +--- com.google.firebase:firebase-messaging:[19.0.0, 22.0.99] -> 19.0.0
| | +--- androidx.collection:collection:1.0.0 (*)
| | +--- androidx.core:core:1.0.0 -> 1.1.0 (*)
| | +--- com.google.android.gms:play-services-basement:17.0.0
| | | +--- androidx.collection:collection:1.0.0 (*)
| | | +--- androidx.core:core:1.0.0 -> 1.1.0 (*)
| | | \--- androidx.fragment:fragment:1.0.0 (*)
| | +--- com.google.android.gms:play-services-tasks:17.0.0
| | | \--- com.google.android.gms:play-services-basement:17.0.0 (*)
| | +--- com.google.firebase:firebase-common:18.0.0
| | | +--- androidx.annotation:annotation:1.0.0 -> 1.1.0
| | | +--- androidx.collection:collection:1.0.0 (*)
| | | +--- androidx.core:core:1.0.0 -> 1.1.0 (*)
| | | +--- com.google.android.gms:play-services-basement:17.0.0 (*)
| | | +--- com.google.android.gms:play-services-tasks:17.0.0 (*)
| | | \--- com.google.auto.value:auto-value-annotations:1.6.3
| | +--- com.google.firebase:firebase-iid:19.0.0
| | | +--- androidx.collection:collection:1.0.0 (*)
| | | +--- androidx.core:core:1.0.0 -> 1.1.0 (*)
| | | +--- androidx.legacy:legacy-support-core-utils:1.0.0 (*)
| | | +--- com.google.android.gms:play-services-basement:17.0.0 (*)
| | | +--- com.google.android.gms:play-services-stats:17.0.0
| | | | +--- androidx.legacy:legacy-support-core-utils:1.0.0 (*)
| | | | \--- com.google.android.gms:play-services-basement:17.0.0 (*)
| | | +--- com.google.android.gms:play-services-tasks:17.0.0 (*)
| | | +--- com.google.firebase:firebase-common:18.0.0 (*)
| | | \--- com.google.firebase:firebase-iid-interop:17.0.0
| | | +--- com.google.android.gms:play-services-base:17.0.0
| | | | +--- androidx.collection:collection:1.0.0 (*)
| | | | +--- androidx.core:core:1.0.0 -> 1.1.0 (*)
| | | | +--- androidx.fragment:fragment:1.0.0 (*)
| | | | +--- com.google.android.gms:play-services-basement:17.0.0 (*)
| | | | \--- com.google.android.gms:play-services-tasks:17.0.0 (*)
| | | \--- com.google.android.gms:play-services-basement:17.0.0 (*)
| | \--- com.google.firebase:firebase-measurement-connector:18.0.0
| | \--- com.google.android.gms:play-services-basement:17.0.0 (*)
| +--- androidx.cardview:cardview:[1.0.0, 1.0.99] -> 1.0.0
| | \--- androidx.annotation:annotation:1.0.0 -> 1.1.0
| +--- androidx.legacy:legacy-support-v4:[1.0.0, 1.0.99] -> 1.0.0
| | +--- androidx.core:core:1.0.0 -> 1.1.0 (*)
| | +--- androidx.media:media:1.0.0
| | | +--- androidx.annotation:annotation:1.0.0 -> 1.1.0
| | | +--- androidx.core:core:1.0.0 -> 1.1.0 (*)
| | | \--- androidx.versionedparcelable:versionedparcelable:1.0.0 -> 1.1.0 (*)
| | +--- androidx.legacy:legacy-support-core-utils:1.0.0 (*)
| | +--- androidx.legacy:legacy-support-core-ui:1.0.0 (*)
| | \--- androidx.fragment:fragment:1.0.0 (*)
| +--- androidx.browser:browser:[1.0.0, 1.3.99] -> 1.3.0
| | +--- androidx.core:core:1.1.0 (*)
| | +--- androidx.annotation:annotation:1.1.0
| | \--- com.google.guava:listenablefuture:1.0
| +--- androidx.appcompat:appcompat:[1.0.0, 1.3.99] -> 1.0.2 (*)
| +--- androidx.work:work-runtime:[2.0.0, 2.5.99] -> 2.5.0
| | +--- com.google.guava:listenablefuture:1.0
| | \--- androidx.lifecycle:lifecycle-livedata:2.1.0 (*)
| +--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.32 (*)
| +--- com.google.android.gms:play-services-base:[17.0.0, 17.6.99] -> 17.0.0 (*)
| \--- androidx.concurrent:concurrent-futures:1.1.0
| +--- androidx.annotation:annotation:1.1.0
| \--- com.google.guava:listenablefuture:1.0
...
+--- project :react-native-camera
| +--- com.google.android.gms:play-services-mlkit-barcode-scanning:16.2.0
| | +--- com.google.android.datatransport:transport-api:2.2.1
| | | \--- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | +--- com.google.android.datatransport:transport-backend-cct:2.3.3
| | | +--- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | | +--- com.google.android.datatransport:transport-api:2.2.1 (*)
| | | +--- com.google.android.datatransport:transport-runtime:2.2.5 -> 2.2.6
| | | | +--- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | | | +--- com.google.android.datatransport:transport-api:2.2.1 (*)
| | | | \--- javax.inject:javax.inject:1
| | | +--- com.google.firebase:firebase-encoders:16.1.0
| | | | \--- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | | \--- com.google.firebase:firebase-encoders-json:17.1.0
| | | +--- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | | \--- com.google.firebase:firebase-encoders:16.1.0 (*)
| | +--- com.google.android.datatransport:transport-runtime:2.2.6 (*)
| | +--- com.google.android.gms:play-services-base:17.6.0
| | | +--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
| | | +--- androidx.core:core:1.2.0 -> 1.5.0 (*)
| | | +--- androidx.fragment:fragment:1.0.0 -> 1.3.4 (*)
| | | +--- com.google.android.gms:play-services-basement:17.6.0
| | | | +--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
| | | | +--- androidx.core:core:1.2.0 -> 1.5.0 (*)
| | | | \--- androidx.fragment:fragment:1.0.0 -> 1.3.4 (*)
| | | \--- com.google.android.gms:play-services-tasks:17.2.1
| | | \--- com.google.android.gms:play-services-basement:17.6.0 (*)
| | +--- com.google.android.gms:play-services-basement:17.6.0 (*)
| | +--- com.google.android.gms:play-services-tasks:17.2.0 -> 17.2.1 (*)
| | +--- com.google.android.odml:image:1.0.0-beta1
| | +--- com.google.firebase:firebase-components:16.1.0
| | | +--- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | | \--- com.google.firebase:firebase-annotations:16.0.0
| | +--- com.google.firebase:firebase-encoders:16.1.0 (*)
| | +--- com.google.firebase:firebase-encoders-json:17.1.0 (*)
| | +--- com.google.mlkit:common:17.2.0
| | | +--- androidx.core:core:1.0.0 -> 1.5.0 (*)
| | | +--- com.google.android.datatransport:transport-api:2.2.1 (*)
| | | +--- com.google.android.datatransport:transport-backend-cct:2.3.3 (*)
| | | +--- com.google.android.datatransport:transport-runtime:2.2.6 (*)
| | | +--- com.google.android.gms:play-services-base:17.6.0 (*)
| | | +--- com.google.android.gms:play-services-basement:17.6.0 (*)
| | | +--- com.google.android.gms:play-services-tasks:17.2.0 -> 17.2.1 (*)
| | | +--- com.google.firebase:firebase-components:16.1.0 (*)
| | | +--- com.google.firebase:firebase-encoders:16.1.0 (*)
| | | \--- com.google.firebase:firebase-encoders-json:17.1.0 (*)
| | \--- com.google.mlkit:vision-common:16.5.0
| | +--- androidx.exifinterface:exifinterface:1.0.0 -> 1.3.2
| | | \--- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | +--- com.google.android.datatransport:transport-api:2.2.1 (*)
| | +--- com.google.android.datatransport:transport-backend-cct:2.3.3 (*)
| | +--- com.google.android.datatransport:transport-runtime:2.2.6 (*)
| | +--- com.google.android.gms:play-services-base:17.6.0 (*)
| | +--- com.google.android.gms:play-services-basement:17.6.0 (*)
| | +--- com.google.android.gms:play-services-tasks:17.2.0 -> 17.2.1 (*)
| | +--- com.google.android.odml:image:1.0.0-beta1
| | +--- com.google.firebase:firebase-components:16.1.0 (*)
| | +--- com.google.firebase:firebase-encoders:16.1.0 (*)
| | +--- com.google.firebase:firebase-encoders-json:17.1.0 (*)
| | \--- com.google.mlkit:common:17.1.1 -> 17.2.0 (*)
| +--- com.google.android.gms:play-services-mlkit-face-detection:16.2.0
| | +--- com.google.android.datatransport:transport-api:2.2.1 (*)
| | +--- com.google.android.datatransport:transport-backend-cct:2.3.3 (*)
| | +--- com.google.android.datatransport:transport-runtime:2.2.6 (*)
| | +--- com.google.android.gms:play-services-base:17.6.0 (*)
| | +--- com.google.android.gms:play-services-basement:17.6.0 (*)
| | +--- com.google.android.gms:play-services-tasks:17.2.0 -> 17.2.1 (*)
| | +--- com.google.android.odml:image:1.0.0-beta1
| | +--- com.google.firebase:firebase-components:16.1.0 (*)
| | +--- com.google.firebase:firebase-encoders:16.1.0 (*)
| | +--- com.google.firebase:firebase-encoders-json:17.1.0 (*)
| | +--- com.google.mlkit:common:17.1.1 -> 17.2.0 (*)
| | \--- com.google.mlkit:vision-common:16.5.0 (*)
| +--- com.facebook.react:react-native:+ -> 0.66.0 (*)
| +--- com.google.zxing:core:3.3.3
| +--- com.drewnoakes:metadata-extractor:2.11.0
| | \--- com.adobe.xmp:xmpcore:5.1.3
| +--- androidx.exifinterface:exifinterface:1.3.2 (*)
| +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| +--- androidx.legacy:legacy-support-v4:1.0.0
| | +--- androidx.core:core:1.0.0 -> 1.5.0 (*)
| | +--- androidx.media:media:1.0.0
| | | +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | | +--- androidx.core:core:1.0.0 -> 1.5.0 (*)
| | | \--- androidx.versionedparcelable:versionedparcelable:1.0.0 -> 1.1.1 (*)
| | +--- androidx.legacy:legacy-support-core-utils:1.0.0
| | | +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | | +--- androidx.core:core:1.0.0 -> 1.5.0 (*)
| | | +--- androidx.documentfile:documentfile:1.0.0
| | | | \--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | | +--- androidx.loader:loader:1.0.0 (*)
| | | +--- androidx.localbroadcastmanager:localbroadcastmanager:1.0.0
| | | | \--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | | \--- androidx.print:print:1.0.0
| | | \--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | +--- androidx.legacy:legacy-support-core-ui:1.0.0
| | | +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | | +--- androidx.core:core:1.0.0 -> 1.5.0 (*)
| | | +--- androidx.legacy:legacy-support-core-utils:1.0.0 (*)
| | | +--- androidx.customview:customview:1.0.0 (*)
| | | +--- androidx.viewpager:viewpager:1.0.0 (*)
| | | +--- androidx.coordinatorlayout:coordinatorlayout:1.0.0 -> 1.1.0
| | | | +--- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | | | +--- androidx.core:core:1.1.0 -> 1.5.0 (*)
| | | | +--- androidx.customview:customview:1.0.0 (*)
| | | | \--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
| | | +--- androidx.drawerlayout:drawerlayout:1.0.0 (*)
| | | +--- androidx.slidingpanelayout:slidingpanelayout:1.0.0
| | | | +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | | | +--- androidx.core:core:1.0.0 -> 1.5.0 (*)
| | | | \--- androidx.customview:customview:1.0.0 (*)
| | | +--- androidx.interpolator:interpolator:1.0.0 (*)
| | | +--- androidx.swiperefreshlayout:swiperefreshlayout:1.0.0 (*)
| | | +--- androidx.asynclayoutinflater:asynclayoutinflater:1.0.0
| | | | +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | | | \--- androidx.core:core:1.0.0 -> 1.5.0 (*)
| | | \--- androidx.cursoradapter:cursoradapter:1.0.0 (*)
| | \--- androidx.fragment:fragment:1.0.0 -> 1.3.4 (*)
| \--- com.google.android.gms:play-services-mlkit-text-recognition:16.3.0
| +--- com.google.android.datatransport:transport-api:2.2.1 (*)
| +--- com.google.android.datatransport:transport-backend-cct:2.3.3 (*)
| +--- com.google.android.datatransport:transport-runtime:2.2.6 (*)
| +--- com.google.android.gms:play-services-base:17.6.0 (*)
| +--- com.google.android.gms:play-services-basement:17.6.0 (*)
| +--- com.google.android.gms:play-services-tasks:17.2.0 -> 17.2.1 (*)
| +--- com.google.android.odml:image:1.0.0-beta1
| +--- com.google.firebase:firebase-components:16.1.0 (*)
| +--- com.google.firebase:firebase-encoders:16.1.0 (*)
| +--- com.google.firebase:firebase-encoders-json:17.1.0 (*)
| +--- com.google.mlkit:common:17.1.1 -> 17.2.0 (*)
| \--- com.google.mlkit:vision-common:16.5.0 (*)
....
- The solution is described here
- Add the following lines to the
dependencies {}
section at the bottom oflc/android/app/build.gradle
:
dependencies {
...
implementation (project(':react-native-camera')) {
exclude group: "com.google.android.gms"
exclude group: "com.google.android.gms", module: "play-services-vision"
exclude group: "com.google.firebase", module: "firebase-ml-vision-face-model"
}
implementation ("com.google.firebase:firebase-ml-vision:19.0.3") {
force = true;
}
implementation ("com.google.firebase:firebase-ml-vision-face-model:17.0.2") {
force = true;
}
...
}
- After running
npx react-native run-android
I ran into a out of memory issue, which I fixed by adding the following lines tolc/android/gradle.properties
:
org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true