Android项目架构搭建

引入依赖库
1 2 3 4 5 6
retrofit okhttp okio RxJava RxAndroid
参考文档
  1. Linux命令大全
  2. Android Gradle Plugin 3.0 implementation、api、compile区别
  3. 给 Android 开发者的 RxJava 详解
  4. RxJava + Retrofit完成网络请求
一、创建项目
  1. 新建SilenceCoder项目,创建时勾选添加Kotlin支持,以便后续扩展。
  2. 创建BaseFeature Library便于以后结构改造成Instant App。
二、配置权限
  1. 网络权限

       
    
三、 在BaseFeature中引入Retrofit 2.x 网络库
  1. 添加依赖

     implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    
  2. Retrofit 混淆配置。
    依赖关系:Retrofit ---->okhttp---->okio。所以相应的混淆都应该添加

     # Platform calls Class.forName on types which do not exist on Android to determine platform.
     -dontnote retrofit2.Platform
     # Platform used when running on Java 8 VMs. Will not be used at runtime.
     -dontwarn retrofit2.Platform$Java8
     # Retain generic type information for use by reflection by converters and adapters.
     -keepattributes Signature
     # Retain declared checked exceptions for use by a Proxy instance.
     -keepattributes Exceptions
    
  3. okhttp 混淆配置

     -dontwarn okhttp3.**
     -dontwarn okio.**
     -dontwarn javax.annotation.**
     -dontwarn org.conscrypt.**
     # A resource is loaded with a relative path so the package of this class must be preserved.
     -keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
    
  4. Okio混淆配置

     -dontwarn okio.**
    
四、在BaseFeature中引入Retrofit Gson Converter,参考retrofit中Converters章节,支持如下Converters:
  • Gson: com.squareup.retrofit2:converter-gson
  • Jackson: com.squareup.retrofit2:converter-jackson
  • Moshi: com.squareup.retrofit2:converter-moshi
  • Protobuf: com.squareup.retrofit2:converter-protobuf
  • Wire: com.squareup.retrofit2:converter-wire
  • Simple XML: com.squareup.retrofit2:converter-simplexml
  • Scalars (primitives, boxed, and String): com.squareup.retrofit2:converter-scalars
五、在BaseFeature中引入RxJava 2.x.y库
  1. 添加依赖

    implementation "io.reactivex.rxjava2:rxjava:2.x.y"
    
六、在BaseFeature中引入RxAndroid库
  1. 添加依赖

     implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
    

你可能感兴趣的:(Android项目架构搭建)