DavidWebb icon indicating copy to clipboard operation
DavidWebb copied to clipboard

Dependency on org.json

Open alewang opened this issue 9 years ago • 7 comments

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 avatar Oct 21 '16 22:10 alewang

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.

alewang avatar Oct 22 '16 00:10 alewang

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?

hgoebl avatar Oct 22 '16 07:10 hgoebl

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

alewang avatar Oct 22 '16 16:10 alewang

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?

hgoebl avatar Oct 24 '16 06:10 hgoebl

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

CapnSpellcheck avatar Oct 26 '16 05:10 CapnSpellcheck

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.

hgoebl avatar Oct 26 '16 06:10 hgoebl

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

pavel-kurnosov avatar Feb 22 '18 21:02 pavel-kurnosov