zoukankan      html  css  js  c++  java
  • RxAndroid+RxJava+Gson+retrofit+okhttp初步搭建android网络请求框架

    新建工程集成,

    一、工具集成(2017-4-27)

    首先第一步集成retrofit 

      retrofit 的 git 网站: https://github.com/square/retrofit

        在git网站上可以看到 Gradle上即成使用  compile 'com.squareup.retrofit2:retrofit:2.2.0'   即可

      retrofit 的 官方网站:http://square.github.io/retrofit/

        在官网上可以看到简单的使用例子以及加载其他内容的方法如图片,

        

     

        按照上述方式集成Gson

    集成Gson(字符串json与对象之间的转换)

      Gson 的 git 网站:https://github.com/google/gson

        在如下图片中可以看到2中学习方式

        

        这边我们选择的是第二种教程方式,点击蓝色链接进入网站,其中市一些使用方法,并且可以找到如下图片方式添加引用

        

        并且根据Retrifit上的gson即成方式进行集成

       compile 'com.google.code.gson:gson:2.8.0'
       compile 'com.squareup.retrofit2:converter-gson:2.2.0'  后面的版本跟retrofit保持一致

    集成Rxjava

      Rxjava git网站:https://github.com/ReactiveX/RxJava/ 

         同理在网站上可以看到集成方式

        

        其中x.y代表了版本,对应retrofit的版本 我们这边选择2开头的版本 其中网站 https://github.com/ReactiveX/RxJava/releases 中为目前发布的版本列表可查看

        这边我们的集成为

     

       compile 'io.reactivex.rxjava2:rxjava:2.0.1'
    集成RxAndroid
      RxAndroid git 网站:https://github.com/ReactiveX/RxAndroid/   
       在网站上的集成方式 

      

        按照方式即成

        compile 'io.reactivex.rxjava2:rxandroid:2.0.1'

    其中如果要在retrofit 中使用rxjava以及rxandroi的话需要集成工具

    compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'   此为集成retrofit2.0的版本

    集成okHttp
    okhttp的git网站 https://github.com/square/okhttp

       网站集成方式

         

       按照方式即成

       compile 'com.squareup.okhttp3:okhttp:3.6.0'

       同时我们还需要okHttp的拦截器

       compile 'com.squareup.okhttp3:logging-interceptor:3.6.0'

    最后我们需要集成一个工具okio,下面我们会讲解为什么用到它  git地址:https://github.com/square/okio

       compile 'com.squareup.okio:okio:1.11.0'

    集成完成后可以看到gradle中的有以下依赖,集成完毕

    compile 'com.squareup.retrofit2:retrofit:2.2.0'
    compile 'com.squareup.retrofit2:converter-gson:2.2.0'
    compile 'com.google.code.gson:gson:2.8.0'
    compile 'com.squareup.okhttp3:okhttp:3.6.0'
    compile 'com.squareup.okhttp3:logging-interceptor:3.6.0'
    compile 'com.squareup.okio:okio:1.11.0'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'io.reactivex.rxjava2:rxjava:2.0.1'
    compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'

    二 运用:(未完待续)

  • 相关阅读:
    字符串提取数字/汉字/英文字母
    CHARINDEX,PATINDEX,STUFF函数
    raiserror的用法
    数据库备份与还原(通过命令)
    查询某个字段属于哪些表
    设备驱动基础1:设备模型之总线,驱动,设备
    设备模型之kobject,kset及其关系
    模拟电路创新设计
    cdev、udev
    PCB阻抗调节
  • 原文地址:https://www.cnblogs.com/minyc/p/myc201704051054.html
Copyright © 2011-2022 走看看