Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

json

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.

  • What went wrong: Execution failed for task ':app:lintVitalRelease'.

    Lint found fatal errors while assembling a release target.

    To proceed, either fix the issues identified by lint, or modify your build script as follows: ... android { lintOptions { checkReleaseBuilds false // Or, if you prefer, you can continue to check for errors in release builds, // but continue the build even when errors are found: abortOnError false } } ...

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

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

like image 913
vanna Avatar asked Oct 30 '17 15:10

vanna


3 Answers

I fixed it by adding:

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

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

like image 52
lxknvlk Avatar answered Nov 07 '22 16:11

lxknvlk


Add this in your app/build.gradle

configurations {
    all {
        exclude module: 'commons-logging'
    }
}
like image 5
Exigente05 Avatar answered Nov 07 '22 16:11

Exigente05


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

./gradlew dependencies
like image 1
codebrane Avatar answered Nov 07 '22 17:11

codebrane