23

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

vanna
  • 949
  • 2
  • 9
  • 16
  • what build tool do you use? – Lino Oct 30 '17 at 15:07
  • I am using Android Studio. Clicked "Build -> Generate Signed APK" – vanna Oct 30 '17 at 15:11
  • Have you solved the problem? I am facing the same issue. – Hong Nov 29 '17 at 13:37
  • 1
    @Hong yes. see my answer below https://stackoverflow.com/a/47019266/271669 – vanna Dec 06 '17 at 07:38
  • Thank you. I assume you solved the problem by removing the dependency. I saw the answer, but I was not sure what you did. I was hoping for a solution without removing any dependencies. – Hong Dec 06 '17 at 11:46
  • Hi, I am getting error at this line "org.json:json:20160212" showing error - Error:(51) 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] while creating Signed APK from AndroidStudio.Please help me.Thanks in Advance – Naveen Dec 20 '17 at 09:37

4 Answers4

30

I fixed it by adding:

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

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

lxknvlk
  • 2,744
  • 1
  • 27
  • 32
5

Add this in your app/build.gradle

configurations {
    all {
        exclude module: 'commons-logging'
    }
}
Exigente05
  • 2,161
  • 3
  • 22
  • 42
1

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

./gradlew dependencies
codebrane
  • 4,290
  • 2
  • 18
  • 27
0

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

compile "me.tatarka.redux:redux-monitor:0.10"
vanna
  • 949
  • 2
  • 9
  • 16