Open alewang opened 8 years ago
I opened a PR to demonstrate what I think dependencies should look like. https://github.com/hgoebl/DavidWebb/pull/25
If my understanding of how Maven (and Gradle for modern Android projects) manages dependencies is correct, then having the JSON library be under the provided scope should allow Android projects to declare a dependency on DavidWebb without having the JSON library also being pulled in.
Thank you very much for contributing. I already tried to solve this (see #3), but without luck. When compiling an Android project with your PR, I still get the same warning:
Warning:WARNING: Dependency org.json:json:20080701 is ignored for debug as it may be conflicting with the internal version provided by Android.
Does this warning disappear when you compile? If no, do you know a solution for this?
Very strange. I don't see that warning at all when I compile.
It's really strange that I still get the warning.
I've posted on Stackoverflow regarding this issue long time ago.
Does anybody know a working solution?
I would like to see no direct dependency on JSON library. I just discovered DavidWebb, but I am writing in Kotlin and wish to use a custom library written in it (klaxon). Perhaps it can be structured into a factory interface where I can provide my own factory if I wish...
org.json is a central part of DavidWebb, because it is meant to be a simple helper for Android projects. Next version will put org.json as provided, so those who do not use any of the JSON* classes and requests/responses have a chance to have smaller dependency footprint. But I'm not going to remove JSON* from DavidWebb source. You can always fork and do your own thing.
BTW for green-field projects I'd recommend using OkHttp rather than DavidWebb.
To fix the problem just add to your app/build.gradle:
configurations { all { exclude module: 'commons-logging' } }
I do not think this library should declare an explicit dependency on org.json since Android also includes org.json as part of its API, as can be seen from https://developer.android.com/reference/org/json/package-summary.html
By adding in a dependency on an external package implementing a similar API, the total size footprint for DavidWebb increases, and we run into potential class loading issues since the org.json package namespace is clobbered with multiple classes with the same name.