新建工程集成,
一、工具集成(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'
二 運用:(未完待續)