Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error [DuplicatePlatformClasses] class conflict when building release on Room persistence

I have used this guide to build persistence with Room in my Android App: https://developer.android.com/training/data-storage/room/index.html

and added dependances like shown here: https://developer.android.com/topic/libraries/architecture/adding-components.html

when i build the debug version and deply to phone, everithing works fine.

When i build the release signed APK i got this error message:

Error:Error: json defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]

my app.gradle:

apply plugin: 'com.android.application'

android {
    signingConfigs {
        /* TODO(developer): Configure to sign app with a release key for testing.
        release {
            storeFile file('path/to/release/signing/key')
            keyAlias 'release_key_alias'
            keyPassword "${password}"
            storePassword "${password}"
        }*/
    }
    compileSdkVersion 26
    buildToolsVersion '26.0.2'

    defaultConfig {
        applicationId "myappid"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 10
        versionName "1.8"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            // TODO(developer): uncomment below once config above is complete and uncommented.
            //signingConfig signingConfigs.release

        }
    }
}
configurations {
    all {
        exclude module: 'httpclient'
    }
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:26.1.0'
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.github.nkzawa:socket.io-client:0.3.0'
    compile 'io.socket:socket.io-client:0.8.3'
    compile 'com.android.support:design:26.1.0'
    compile 'android.arch.persistence.room:runtime:1.0.0'
    implementation "android.arch.persistence.room:runtime:1.0.0"
    annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
}

my project.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        //classpath 'io.socket:socket.io-client:0.8.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
ext{
    roomVersion = '1.0.0'
}
allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.google.com' }
    }
}

Somebody can help or give me clues?

like image 563
Romeo Avatar asked Nov 16 '17 18:11

Romeo


2 Answers

I finally found the problem was a JSON sub-module:

compile 'com.github.nkzawa:socket.io-client:0.3.0'

this library has a submodule:

org.json:json

that is now conflicting with android native module, because in my other dependancies i can't find this one. It was working fine 10 days ago. I also had to kill this:

compile 'io.socket:socket.io-client:0.8.3'

the final solution was to add an exclude for the module and change the line like this:

    implementation ('com.github.nkzawa:socket.io-client:0.3.0',{
         exclude group:'org.json', module:'json'
    })

I also have noticed AFTER i solved the problem that in the error log it was suggesting me the module that was in conflict but even if i read it a hundred times i didn't noticed before: enter image description here

so maybe google or Intellij could improve the writing of this errors...

To spot this class duplicate conflict error module i found the best way to proceed is to create a new project and paste in the dependancies in app build.gradle, and check them one by one or with "dividi et impera", maybe this is an obvious suggestion for someone but i would have like to have it sooner.

like image 66
Romeo Avatar answered Nov 15 '22 16:11

Romeo


I had the same problem and I searched for the conflict via the gradle dependency tree:

gradlew app:dependencies

Then I excluded the the json module for the conflicting library:

implementation ('<conflicting-library>',{
     exclude group:'org.json', module:'json'
})
like image 4
Manuel Schmitzberger Avatar answered Nov 15 '22 16:11

Manuel Schmitzberger