Home > Back-end >  Gradle error after adding discord4j library
Gradle error after adding discord4j library

Time:03-10

I am trying to build an discord bot with discord4j. I added this line of code to the build.gradle file.

dependencies {
    implementation "com.discord4j:discord4j-core:3.2.2"
}

However, after I try to build the app, the build failed at task :app:checkDebugDuplicateClasses.

* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class com.iwebpp.crypto.TweetNaclFast found in modules discord4j-rest-3.2 (com.discord4j:discord4j-rest:3.2.2) and discord4j-voice-3.2 (com.discord4j:discord4j-voice:3.2.2)
     Duplicate class com.iwebpp.crypto.TweetNaclFast$Box found in modules discord4j-rest-3.2 (com.discord4j:discord4j-rest:3.2.2) and discord4j-voice-3.2 (com.discord4j:discord4j-voice:3.2.2)
     Duplicate class com.iwebpp.crypto.TweetNaclFast$Box$KeyPair found in modules discord4j-rest-3.2 (com.discord4j:discord4j-rest:3.2.2) and discord4j-voice-3.2 (com.discord4j:discord4j-voice:3.2.2)
     Duplicate class com.iwebpp.crypto.TweetNaclFast$Hash found in modules discord4j-rest-3.2 (com.discord4j:discord4j-rest:3.2.2) and discord4j-voice-3.2 (com.discord4j:discord4j-voice:3.2.2)
     Duplicate class com.iwebpp.crypto.TweetNaclFast$ScalarMult found in modules discord4j-rest-3.2 (com.discord4j:discord4j-rest:3.2.2) and discord4j-voice-3.2 (com.discord4j:discord4j-voice:3.2.2)
     Duplicate class com.iwebpp.crypto.TweetNaclFast$SecretBox found in modules discord4j-rest-3.2 (com.discord4j:discord4j-rest:3.2.2) and discord4j-voice-3.2 (com.discord4j:discord4j-voice:3.2.2)
     Duplicate class com.iwebpp.crypto.TweetNaclFast$Signature found in modules discord4j-rest-3.2 (com.discord4j:discord4j-rest:3.2.2) and discord4j-voice-3.2 (com.discord4j:discord4j-voice:3.2.2)
     Duplicate class com.iwebpp.crypto.TweetNaclFast$Signature$KeyPair found in modules discord4j-rest-3.2 (com.discord4j:discord4j-rest:3.2.2) and discord4j-voice-3.2 (com.discord4j:discord4j-voice:3.2.2)
     Duplicate class com.iwebpp.crypto.TweetNaclFast$poly1305 found in modules discord4j-rest-3.2 (com.discord4j:discord4j-rest:3.2.2) and discord4j-voice-3.2 (com.discord4j:discord4j-voice:3.2.2)
     
     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 --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:checkDebugDuplicateClasses'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:188)
    at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:186)
    at ...
    
Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
    at org.gradle.workers.internal.DefaultWorkerExecutor$WorkItemExecution.waitForCompletion(DefaultWorkerExecutor.java:342)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:142)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:94)
    at ...
    
Caused by: java.lang.RuntimeException: Duplicate class com.iwebpp.crypto.TweetNaclFast found in modules discord4j-rest-3.2 (com.discord4j:discord4j-rest:3.2.2) and discord4j-voice-3.2 (com.discord4j:discord4j-voice:3.2.2)
Duplicate class com.iwebpp.crypto.TweetNaclFast$Box found in modules discord4j-rest-3.2 (com.discord4j:discord4j-rest:3.2.2) and discord4j-voice-3.2 (com.discord4j:discord4j-voice:3.2.2)
Duplicate class com.iwebpp.crypto.TweetNaclFast$Box$KeyPair found in modules discord4j-rest-3.2 (com.discord4j:discord4j-rest:3.2.2) and discord4j-voice-3.2 (com.discord4j:discord4j-voice:3.2.2)
Duplicate class com.iwebpp.crypto.TweetNaclFast$Hash found in modules discord4j-rest-3.2 (com.discord4j:discord4j-rest:3.2.2) and discord4j-voice-3.2 (com.discord4j:discord4j-voice:3.2.2)
Duplicate class com.iwebpp.crypto.TweetNaclFast$ScalarMult found in modules discord4j-rest-3.2 (com.discord4j:discord4j-rest:3.2.2) and discord4j-voice-3.2 (com.discord4j:discord4j-voice:3.2.2)
Duplicate class com.iwebpp.crypto.TweetNaclFast$SecretBox found in modules discord4j-rest-3.2 (com.discord4j:discord4j-rest:3.2.2) and discord4j-voice-3.2 (com.discord4j:discord4j-voice:3.2.2)
Duplicate class com.iwebpp.crypto.TweetNaclFast$Signature found in modules discord4j-rest-3.2 (com.discord4j:discord4j-rest:3.2.2) and discord4j-voice-3.2 (com.discord4j:discord4j-voice:3.2.2)
Duplicate class com.iwebpp.crypto.TweetNaclFast$Signature$KeyPair found in modules discord4j-rest-3.2 (com.discord4j:discord4j-rest:3.2.2) and discord4j-voice-3.2 (com.discord4j:discord4j-voice:3.2.2)
Duplicate class com.iwebpp.crypto.TweetNaclFast$poly1305 found in modules discord4j-rest-3.2 (com.discord4j:discord4j-rest:3.2.2) and discord4j-voice-3.2 (com.discord4j:discord4j-voice:3.2.2)

Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.
    at com.android.build.gradle.internal.tasks.CheckDuplicateClassesDelegate.run(CheckDuplicateClassesDelegate.kt:71)
    at com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable.execute(CheckDuplicateClassesDelegate.kt:98)
    at ...


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

BUILD FAILED in 6s

I noticed that there is a duplicate class in modules discord4j-rest and discord4j-voice. After searching for the solutions, I found this answer:

Sometimes duplicate classes exception means that one of your dependencies uses implicitly the older or newer (with ) version of some library you also use in your project,

However, these 2 modules are the dependencies of discord4j. Therefore, I am not able to use the force function with them. How can I solve this problem?

CodePudding user response:

I'm one of the developers for Discord4J and have pushed a fix moving the affected class to a shared module.

Until there's a stable version including it, you could switch to the latest snapshot to try it.

repositories {
  maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
  mavenCentral()
}

dependencies {
  implementation 'com.discord4j:discord4j-core:3.2.3-SNAPSHOT'
}

From: https://docs.discord4j.com/using-snapshots/

  • Related