vanna
vanna

Reputation: 1049

Error: json defines classes that conflict with classes now provided by Android

I got the following error when doing a release build on Android Studio 3

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]

The following is my dependencies:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.0.1'
    compile 'com.android.support:support-v4:26.0.1'
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
    compile 'com.evernote:android-job:1.2.0'
    compile 'com.amitshekhar.android:android-networking:1.0.0'
    compile 'com.facebook.stetho:stetho:1.5.0'
    compile "me.tatarka.redux:redux-core:0.10"
    compile "me.tatarka.redux:redux-android:0.10"
    compile "me.tatarka.redux:redux-android-lifecycle:0.10"
    compile "me.tatarka.redux:redux-thunk:0.10"
    annotationProcessor "org.immutables:value:2.5.5" // <-- for annotation processor
    provided "org.immutables:value:2.5.5" // for annotations
    provided "org.immutables:builder:2.5.5" // for annotations

    compile "me.tatarka.redux:redux-monitor:0.10"
    testCompile 'junit:junit:4.12'
}

It's saying json but I can't find which of the the above dependencies is causing the problem.

Here is what I get when I run

gradlew assembleRelease

Task :app:lintVitalRelease /Users/kruyvanna/Projects/key/HappyKey_Android2/app/build.gradle: 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]

Explanation for issues of type "DuplicatePlatformClasses": There are a number of libraries that duplicate not just functionality of the Android platform but using the exact same class names as the ones provided in Android -- for example the apache http classes. This can lead to unexpected crashes.

To solve this, you need to either find a newer version of the library which no longer has this problem, or to repackage the library (and all of its dependencies) using something like the jarjar tool, or finally, rewriting the code to use different APIs (for example, for http code, consider using HttpUrlConnection or a library like okhttp.)

1 errors, 0 warnings

FAILURE: Build failed with an exception.

Upvotes: 24

Views: 12650

Answers (4)

Exigente05
Exigente05

Reputation: 2211

Add this in your app/build.gradle

configurations {
    all {
        exclude module: 'commons-logging'
    }
}

Upvotes: 5

lxknvlk
lxknvlk

Reputation: 2850

I fixed it by adding:

configurations {
    all {
        exclude group: 'org.json', module: 'json'
    }
}

to module gradle file, no removal of dependencies was needed.

Upvotes: 33

vanna
vanna

Reputation: 1049

I added dependencies one by one and found this one causing the error

compile "me.tatarka.redux:redux-monitor:0.10"

Upvotes: 0

codebrane
codebrane

Reputation: 4630

Go to the commandline and look at the dependency tree. This will give you a list of everything that your app uses:

./gradlew dependencies

Upvotes: 1

Related Questions