问题
// Retrofit
compile 'com.squareup.retrofit2:retrofit:2.1.0'
// JSON Parsing
compile 'com.google.code.gson:gson:2.6.1'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
My question is regarding the second and third dependency added. I do understand it is related to JSON conversion. If the third dependency is added,would the second dependency still be needed?
I have seen them both being added on several examples. For e.g: https://www.androidhive.info/2016/05/android-working-with-retrofit-http-library/ https://code.tutsplus.com/tutorials/sending-data-with-retrofit-2-http-client-for-android--cms-27845
回答1:
At the source of Retrofit Gson contverter library, there is a dependency of Gson.
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
So, when you include com.squareup.retrofit2:converter-gson
as your dependency, com.google.code.gson:gson
will be automatically included.
So, you will not need to include the Gson
dependency explicitly.
来源:https://stackoverflow.com/questions/49399098/what-is-the-role-of-com-google-code-gsongson2-6-1-dependency-in-retrofit-2-w