Gradle 的配置和引用

我们的Android studio工程有时会存在很多共同的构建包

这里我会新建一个gradle 文件

config.gradle

ext{
    android = [
            applicationId     : "net.huansi.loosecloth",
            compileSdkVersion : 28,
            minSdkVersion     : 15,
            targetSdkVersion  : 28,
            versionCode       : 1,
            versionName       : "1.0",
            support           : "28.0.0"
    ]
    def dependVersion = [
            baseform          : "19.6.6.1-SNAPSHOT",
            retrofit          : "2.2.0",
            okhttp            : "3.6.0",
            dagger2           : "2.7",
            butterknife       : "8.6.0",
            glide             : "4.5.0",
    ]

    var = [
            //base
            appcompat_v7              : "com.android.support:appcompat-v7:${android.support}",
            cardview_v7               : "com.android.support:cardview-v7:${android.support}",
            recyclerview_v7           : "com.android.support:recyclerview-v7:${android.support}",
            design                    : "com.android.support:design:${android.support}",
            rv_adapter_helper         : "com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.42",
            base_form                 : "baseform.android.huansi.net:baseform:${dependVersion.baseform}",

            //rx
            rxjava                    : "io.reactivex.rxjava2:rxjava:2.2.2",
            rxandroid                 : "io.reactivex.rxjava2:rxandroid:2.0.1",
            rxpermissions             : "com.tbruyelle.rxpermissions2:rxpermissions:0.9.3@aar",

            //network
            gson                      : "com.google.code.gson:gson:2.8.2",
            retrofit                  : "com.squareup.retrofit2:retrofit:${dependVersion.retrofit}",
            retrofit_converter_gson   : "com.squareup.retrofit2:converter-gson:${dependVersion.retrofit}",
            retrofit_adapter_rxjava2  : "com.squareup.retrofit2:adapter-rxjava2:${dependVersion.retrofit}",
            okhttp                    : "com.squareup.okhttp3:okhttp:${dependVersion.okhttp}",
            okhttp_logging_interceptor: "com.squareup.okhttp3:logging-interceptor:${dependVersion.okhttp}",
            glide                     : "com.github.bumptech.glide:glide:${dependVersion.glide}",
            glide_compiler            : "com.github.bumptech.glide:compiler:${dependVersion.glide}",
            glide_transformations     : "jp.wasabeef:glide-transformations:3.0.1",

            //di
            dagger                    : "com.google.dagger:dagger:${dependVersion.dagger2}",
            dagger_compiler           : "com.google.dagger:dagger-compiler:${dependVersion.dagger2}",
            butterknife               : "com.jakewharton:butterknife:${dependVersion.butterknife}",
            butterknife_compiler      : "com.jakewharton:butterknife-compiler:${dependVersion.butterknife}",

            //other
            multidex                  : "com.android.support:multidex:1.0.3",
            smart_refresh             : "com.scwang.smartrefresh:SmartRefreshLayout:1.0.5.1",
            //滑动轮
            wheelview                 : "com.contrarywind:wheelview:4.0.5",
            //相册选择
            picture_selector          : "com.github.LuckSiege.PictureSelector:picture_library:v2.2.0",
            //dialog管理
            material_dialog           : "com.afollestad.material-dialogs:core:0.9.6.0",

            constraint                : "com.android.support.constraint:constraint-layout:1.1.3",
            autofittextview           : "me.grantland:autofittextview:0.2.1"
    ]

}

然后在工程的build.gradle中引用

Gradle 的配置和引用_第1张图片

Gradle 的配置和引用_第2张图片

 

apply from :"config.gradle"

 

应用到各个module中引用

Gradle 的配置和引用_第3张图片

 

转载于:https://www.cnblogs.com/woaixingxing/p/11009704.html

你可能感兴趣的:(java,移动开发)