官术网_书友最值得收藏!

Additional libraries

We configured our build types and flavors, now we will need some third-party libraries. We will use and add support for Retrofit, OkHttp, and Gson. This is an explanation for each of them:

  • Retrofit is a type-safe HTTP client for Android and Java by Square, Inc. Retrofit is one of the most popular HTTP client library for Android as a result of its simplicity and its great performance compared to the others.
  • OkHttp is an HTTP client that's efficient by default--HTTP/2 support allows all requests to the same host to share a socket.
  • Gson is a Java library that can be used to convert Java objects into their JSON representation. It can also be used to convert a JSON string to an equivalent Java object. Gson can work with arbitrary Java objects including preexisting objects that you do not have a source code for.

There are a few open source projects that can convert Java objects to JSON. Later in this book, we will add Kotson to provide Gson bindings for Kotlin.

Let's extend build.gradle with dependencies for Retrofit and Gson:

    dependencies { 
      ... 
      compile 'com.google.code.gson:gson:2.8.0' 
      compile 'com.squareup.retrofit2:retrofit:2.2.0' 
      compile 'com.squareup.retrofit2:converter-gson:2.0.2' 
      compile 'com.squareup.okhttp3:okhttp:3.6.0' 
      compile 'com.squareup.okhttp3:logging-interceptor:3.6.0' 
      ... 
    } 

After you updated your Gradle configuration, sync it again when asked!

主站蜘蛛池模板: 黎川县| 河南省| 荣昌县| 南郑县| 射阳县| 嵊州市| 公主岭市| 朔州市| 杨浦区| 古交市| 阳东县| 偃师市| 水富县| 南乐县| 儋州市| 定远县| 锦州市| 桃江县| 北碚区| 华蓥市| 斗六市| 拜泉县| 乐昌市| 綦江县| 德令哈市| 松溪县| 河池市| 喜德县| 六盘水市| 乌苏市| 于田县| 甘谷县| 台江县| 宜昌市| 达拉特旗| 青铜峡市| 楚雄市| 徐闻县| 闵行区| 深泽县| 崇文区|