React Native :app:checkDebugDuplicateClasses FAILED - android

I'm trying to implement a Trustmanager for websocket connections in a React Native project by directly adopting the code from this gist. It requires the okhttp-ws module to run.
But, it fails at :app:checkDebugDuplicateClasses
Execution failed for task ':app:checkDebugDuplicateClasses'.
> 1 exception was raised by workers:
java.lang.RuntimeException: java.lang.RuntimeException:
Duplicate class okhttp3.internal.ws.RealWebSocket found in modules okhttp-3.14.1.jar (com.squareup.okhttp3:okhttp:3.14.1) and okhttp-ws-3.4.2.jar (com.squareup.okhttp3:okhttp-ws:3.4.2)
Duplicate class okhttp3.internal.ws.RealWebSocket$1 found in modules okhttp-3.14.1.jar (com.squareup.okhttp3:okhttp:3.14.1) and okhttp-ws-3.4.2.jar (com.squareup.okhttp3:okhttp-ws:3.4.2)
Duplicate class okhttp3.internal.ws.WebSocketProtocol found in modules okhttp-3.14.1.jar (com.squareup.okhttp3:okhttp:3.14.1) and okhttp-ws-3.4.2.jar (com.squareup.okhttp3:okhttp-ws:3.4.2)
Duplicate class okhttp3.internal.ws.WebSocketReader found in modules okhttp-3.14.1.jar (com.squareup.okhttp3:okhttp:3.14.1) and okhttp-ws-3.4.2.jar (com.squareup.okhttp3:okhttp-ws:3.4.2)
Duplicate class okhttp3.internal.ws.WebSocketReader$FrameCallback found in modules okhttp-3.14.1.jar (com.squareup.okhttp3:okhttp:3.14.1) and okhttp-ws-3.4.2.jar (com.squareup.okhttp3:okhttp-ws:3.4.2)
Duplicate class okhttp3.internal.ws.WebSocketWriter found in modules okhttp-3.14.1.jar (com.squareup.okhttp3:okhttp:3.14.1) and okhttp-ws-3.4.2.jar (com.squareup.okhttp3:okhttp-ws:3.4.2)
Duplicate class okhttp3.internal.ws.WebSocketWriter$FrameSink found in modules okhttp-3.14.1.jar (com.squareup.okhttp3:okhttp:3.14.1) and okhttp-ws-3.4.2.jar (com.squareup.okhttp3:okhttp-ws:3.4.2)
So, I excluded okhttp from app/build.gradle
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
// compile the ws module
implementation('com.squareup.okhttp3:okhttp-ws:+'){
// exclude the conflicting module
exclude group:'com.squareup.okhttp3', module:'okhttp'
}
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'
// interestingly, it's been excluded here too
exclude group:'com.squareup.okhttp3', module:'okhttp'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
Still, I get the same error. So, I visited the developer docs link that the error shows and tried searching for the Class okhttp3.internal.ws.RealWebSocket in Android Studio. But it only shows some files from cache folder containing the troublesome Class, both of okhttp and ws modules, which I can't delete these files. For other classes, it just shows files from the okhttp module only, which I can't delete either. Is there a workaround to this? What am I missing?

WebSocket is now part of the core library. https://square.github.io/okhttp/4.x/okhttp/okhttp3/-web-socket/
So you should upgrade to 4.9.0 and stop depending on okhttp-ws, or revert to 3.12.12 (which is a supported legacy branch).
There is a sample here of how to use the WebSocket support in OkHttp https://github.com/square/okhttp/blob/master/samples/slack/src/main/java/okhttp3/slack/SlackApi.java
Or use the built in react-native support https://reactnative.dev/docs/network

Related

Duplicate class com.google.firebase.iid.FirebaseInstanceIdReceiver found in modules

Duplicate class com.google.firebase.iid.FirebaseInstanceIdReceiver found in modules jetified-firebase-iid-20.1.5-runtime (com.google.firebase:firebase-iid:20.1.5) and jetified-firebase-messaging-23.1.1-runtime (com.google.firebase:firebase-messaging:23.1.1)
I'm trying to integrate the Carrot Quest library and I'm facing a dependency conflict problem.
I tried to do exclude group, but without success
`
implementation ('io.carrotquest:android-sdk:1.0.60-commonRelease') {
exclude group: 'com.google.firebase'
}
`

How to exclude Duplicate Class without changing Version

I'm using Coroutine and Paging 3 Libary on my project on changing new Version of libary most of the time i will get this Duplicate Class Error , So what is the proper way to get rid of such problems with changing library version...
Duplicate class kotlinx.coroutines.AbstractCoroutine found in modules jetified-kotlinx-
coroutines-core-jvm-1.4.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.4.1) and
jetified-kotlinx-coroutines-core-jvm-1.4.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-
core:1.4.1)
Duplicate class kotlinx.coroutines.Active found in modules jetified-kotlinx-coroutines-core-
jvm-1.4.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.4.1) and jetified-kotlinx-
coroutines-core-jvm-1.4.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1)
Duplicate class kotlinx.coroutines.AwaitAll found in modules jetified-kotlinx-coroutines-core-
jvm-1.4.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.4.1) and jetified-kotlinx-
coroutines-core-jvm-1.4.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1)
Duplicate class kotlinx.coroutines.AwaitAll$AwaitAllNode found in modules jetified-kotlinx-
coroutines-core-jvm-1.4.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.4.1) and
jetified-kotlinx-coroutines-core-jvm-1.4.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-
core:1.4.1)
I resolved it.
def paging_version_3 = "3.0.0-alpha12"
implementation ("androidx.paging:paging-runtime-ktx:$paging_version_3")
{
exclude group: 'org.jetbrains.kotlinx', module: 'kotlinx-coroutines-core-jvm'
}
// optional - RxJava3 support
implementation ("androidx.paging:paging-rxjava3:$paging_version_3")
{
exclude group: 'org.jetbrains.kotlinx', module: 'kotlinx-coroutines-core-jvm'
}
// leanback paging library
implementation ("androidx.leanback:leanback-paging:1.1.0-alpha07")
{
exclude group: 'org.jetbrains.kotlinx', module: 'kotlinx-coroutines-core-jvm'
}
exclude group: 'org.jetbrains.kotlinx', module: 'kotlinx-coroutines-core-jvm'
You can remove and clear the cache and recompile it , under the Gradle Plugin module,find the Dependencies under Help

Duplicate class using product flavours

My android gradle build has many flavours.
One of then has an aar file that contains a duplicate dependency (com.google.zxing).
build.gradle:
...
dependencies {
implementation 'com.google.zxing:core:3.3.3'
implementation 'me.dm7.barcodescanner:zxing:1.9.8'
// Standard flavour
standardImplementation(name: 'libgedi-0.190121.gpos800', ext: 'aar') {
exclude group: 'com.google.zxing', module: 'android-core'
transitive = false
}
...
}
This configuration produces the following for "standard" build (works for another flavours):
Duplicate class com.google.zxing.BarcodeFormat found in modules core-3.3.3.jar (com.google.zxing:core:3.3.3) and zxing-2.1.jar (:libgedi-0.190121.gpos800:)
Duplicate class com.google.zxing.Binarizer found in modules core-3.3.3.jar (com.google.zxing:core:3.3.3) and zxing-2.1.jar (:libgedi-0.190121.gpos800:)
Duplicate class com.google.zxing.BinaryBitmap found in modules core-3.3.3.jar (com.google.zxing:core:3.3.3) and zxing-2.1.jar (:libgedi-0.190121.gpos800:)
Duplicate class com.google.zxing.ChecksumException found in modules core-3.3.3.jar (com.google.zxing:core:3.3.3) and zxing-2.1.jar (:libgedi-0.190121.gpos8
...
I tried to change the config to:
standardImplementation(name: 'libgedi-0.190121.gpos800', ext: 'aar') {
configurations {
all*.exclude group: 'com.google.zxing'
}
}
The config above works only when i'm build the "standard" flavour. To another flavors, this error occurs:
error: package com.google.zxing.qrcode.decoder does not exist
What i'm doing wrong?
Solution:
{
configurations {
exclude group: 'com.google.zxing'
}
}
use exclude instead all*exclude

How to exclude certain part of a gradle dependecy?

Multiple dependencies has similar named class and I'm getting duplicate class errors. To solve I think excluding those parts may help. How to exclude these parts?
Errors +lots of similar lines:
Duplicate class com.google.protobuf.AbstractMessageLite found in modules protobuf-java-3.7.1.jar (com.google.protobuf:protobuf-java:3.7.1) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.AbstractMessageLite$Builder found in modules protobuf-java-3.7.1.jar (com.google.protobuf:protobuf-java:3.7.1) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.AbstractMessageLite$Builder$LimitedInputStream found in modules protobuf-java-3.7.1.jar (com.google.protobuf:protobuf-java:3.7.1) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Dependencies:
// gRPC
implementation "io.grpc:grpc-okhttp:$grpcVersion"
implementation "io.grpc:grpc-protobuf-lite:$grpcVersion"
implementation "io.grpc:grpc-stub:$grpcVersion"
implementation 'javax.annotation:javax.annotation-api:1.3.2'
//protobuf 'com.google.protobuf:protobuf-java:3.8.0'//error persist with this and without this
// OAuth2 for Google API
implementation('com.google.auth:google-auth-library-oauth2-http:0.7.0') {
exclude module: 'httpclient'
}
//Translation
implementation "com.google.cloud:google-cloud-translate:$grpcVersion"
implementation('com.google.cloud:google-cloud-translate:1.79.0') {
exclude group: 'org.apache.httpcomponents'
exclude group: 'org.json', module: 'json'
//I want to exclude error classes here...HOW?...
//exclude group: 'com.google.protobuf', module: 'protobuf-java-3.7.1'
}
annotationProcessor "com.google.cloud:google-cloud-translate:$grpcVersion"
grpc version on ext:
grpcVersion = '1.4.0'
these are not related to support library versions as these are because of translation and protobuf-lite libraries. these are using different versions of those class and I dont know if excluding of them will work or not.
Is it possible to extract those libraries and change those class names?
I want to see if excluding those classes can solve it. How to exclude?

Why I'm Getting Duplicate Class When Running My Android Project

I'm in the process of adding a navigation drawer to my app. and I'm getting errors. The app gradle synchs just fine. but when I run the app I get a bunch of duplicate class error. I think it might be because I have conflicting dependencies added and that I'm using v7 28.0.0 and some of the errors mention app: v4. all the examples I've seen online use v7 28.0.0 eventhough I have this in main_activity.xml which uses v4. don't know if it's got something to do with the error. android.support.v4.widget.DrawerLayout
Caused by: com.android.ide.common.workers.WorkerExecutorException: 1 exception was raised by workers:
java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle$Delegate found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle$DelegateProvider found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle$SlideDrawable found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActivityCompat found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActivityCompat$1 found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActivityCompat$OnRequestPermissionsResultCallback found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "org.pctechtips.netdroid"
minSdkVersion 21
targetSdkVersion 28
versionCode 8
versionName "1.7"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled = false
signingConfig signingConfigs.config
}
buildTypes {
release {
shrinkResources false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable false
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
/*androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
firebase
implementation 'com.google.firebase:firebase-core:10.2.1'
})*/
// compile 'com.android.support:appcompat-v7:25.3.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
/*google play plugin for adMob*/
implementation 'com.google.android.gms:play-services:10.2.1'
implementation 'commons-net:commons-net:3.6'
implementation 'org.samba.jcifs:jcifs:1.3.3'
}
The exception means, There were duplicated classes in 2 or more different dependencies and the compiler wouldn't be able to distinguish which of them should be used at run-time and the exception was thrown.
Most often, Duplicity happens when you are trying to import modules that carrying their required libraries. (transitive dependencies)
You have to exclude duplicated classes from libraries in the build.gradle.
As Log shows, support-core-ui and support-compat modules have duplicated classes.
apply plugin: 'com.android.application'
android {
...
defaultConfig {
...
}
buildTypes {
...
}
configurations {
all { // You should exclude one of them not both of them
exclude group: "com.android.support", module: "support-core-ui"
exclude group: "com.android.support", module: "support-compat"
}
}
}
Sometimes you don't need to exclude anything and you only need to change the imported module to that one that does not bring its dependencies.
Other situation that causes duplicated classes is when you have added *.jar to the project libs directory. Therefore, You need to delete them if they are not begin used in the project.
project->app->libs->*.jar
I see there are some solutions mentioned using these 2 lines will resolve the problem But if you've migrated to Androidx it would be enabled by default.
android.useAndroidX=true
android.enableJetifier=true
Jetifier is
Jetifier tool migrates support-library-dependent libraries to rely on
the equivalent AndroidX packages instead. The tool lets you migrate an
individual library directly, instead of using the Android gradle
plugin bundled with Android Studio.
And for more information take a look at Exclude transitive dependencies
As an app grows in scope, it can contain a number of dependencies
including direct dependencies and transitive dependencies (libraries
which your app's imported libraries depend on). To exclude transitive
dependencies that you no longer need, you can use the exclude
keyword
If you have problems excluding classes, check this thread: How do I exclude...
See if adding this dependency works:
implementation 'com.android.support:support-v4:28.0.0'
Go to gradle.properties and write these two lines of code:
android.useAndroidX=true
android.enableJetifier=true
Please update com.google.android.gms:play-services to latest version. it wil work.
I tried all above solution, but nothing worked in my case. What worked for me is.
I got this problem resolved by creating a new project with the same project and package name and then copying files from the previous project to new one.

Categories

Resources