hgoebl / DavidWebb

Lightweight Java HTTP-Client for calling JSON REST-Services (especially for Android)
https://hgoebl.github.io/DavidWebb/
MIT License
127 stars 41 forks source link

Dependency on org.json #24

Open alewang opened 8 years ago

alewang commented 8 years ago

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.

alewang commented 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.

hgoebl commented 8 years ago

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?

alewang commented 8 years ago

Very strange. I don't see that warning at all when I compile.

hgoebl commented 8 years ago

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?

CapnSpellcheck commented 8 years ago

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...

hgoebl commented 8 years ago

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.

pavel-kurnosov commented 6 years ago

To fix the problem just add to your app/build.gradle: configurations { all { exclude module: 'commons-logging' } }