// 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'
我的问题是关于添加的第二个和第三个依赖项。我知道它与 JSON 转换有关。如果加上第三个依赖,还需要第二个依赖吗?
我已经看到它们都被添加到几个示例中。 例如: 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
最佳答案
在 source Retrofit Gson converter library,有一个Gson的依赖。
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
因此,当您将 com.squareup.retrofit2:converter-gson
作为您的依赖项时,com.google.code.gson:gson
将自动包括在内。
因此,您不需要显式地包含 Gson
依赖项。
关于android - 'com.google.code.gson:gson:2.6.1' 依赖在 retrofit 2 自带 gson 转换器的情况下有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49399098/