Android 构建配置文件(config.gradle)

2023-11-17

1、新建config.gradle

在自己的项目根目录下一个文件夹下创建一个config.gradle文件名的文件(和settings.gradble同目录),把自己需要用到的库跟版本号写在dependencies 标签括号内

ext {
    android = [
            compileSdkVersion   : 31,
            buildToolsVersion   : '31.0.0',
            applicationId       : 'com.jinfeng.gongshigonggao',
            minSdkVersion       : 24,
            targetSdkVersion    : 31,
            versionCode         : 1,
            versionName         : '1.0',
            defaultPublishConfig: 'release',
            publishNonDefault   : true
    ]
    androidxVersion = [
            appcompat         : "1.2.0",
            recycleviewVersion: "1.0.0",
            annotations       : "1.1.0"
    ]

    version = [
            androidSupportSdkVersion: "29.0.0",
            retrofitSdkVersion      : "2.9.0",
            dagger2SdkVersion       : "2.19",
            glideSdkVersion         : "4.14.2",
            fragmentationVersion    : "1.0.0",
            butterknifeSdkVersion   : "10.0.0",
            baseRecycleViewVersion  : "2.9.34",
            rxlifecycleSdkVersion   : "1.0",
            rxlifecycle2SdkVersion  : "2.2.2",
            espressoSdkVersion      : "3.0.1",
            canarySdkVersion        : "1.5.4",
            arouterSDk              : "1.4.1",
            arouterCompilerSdk      : "1.2.2",
            roomVersion             : "1.1.1",
            okhttp3Version          : "4.10.0"
            navVersion              : "2.1.0"
    ]

    dependencies = [
            //support
            "design"                   : "com.android.support:design:${version["androidSupportSdkVersion"]}",
            "appcompat"                : "androidx.appcompat:appcompat:${androidxVersion["appcompat"]}",
            "material"                 : "com.google.android.material:material:1.3.0",
            "constraintlayout"         : "androidx.constraintlayout:constraintlayout:2.0.4",
            "junit"                    : "junit:junit:4.12",
            "testJunit"                : "androidx.test.ext:junit:1.1.2",
            "testEspresso"             : "androidx.test.espresso:espresso-core:3.3.0",

            //network
            "retrofit"                  : "com.squareup.retrofit2:retrofit:${version["retrofitSdkVersion"]}",
            "retrofitConverterGson"     : "com.squareup.retrofit2:converter-gson:${version["retrofitSdkVersion"]}",
            "retrofitAdapterRxjava"     : "com.squareup.retrofit2:adapter-rxjava:${version["retrofitSdkVersion"]}",
            "retrofitAdapterRxjava2"    : "com.squareup.retrofit2:adapter-rxjava2:${version["retrofitSdkVersion"]}",

            "okhttp3"                   : "com.squareup.okhttp3:okhttp:${version["okhttp3Version"]}",
            "okhttp3LoggingInterceptor" : "com.squareup.okhttp3:logging-interceptor:${version["okhttp3Version"]}",
            "okhttpUrlconnection"       : "com.squareup.okhttp:okhttp-urlconnection:2.0.0",

            //rx2
            "rxjava2"                  : "io.reactivex.rxjava2:rxjava:2.2.4",
            "rxandroid2"               : "io.reactivex.rxjava2:rxandroid:2.1.0",

            //rx1
            "rxjava"                   : "io.reactivex:rxjava:1.3.0",
            "rxandroid"                : "io.reactivex:rxandroid:1.2.1",

            //Room
            "roomRuntime"              : "android.arch.persistence.room:runtime:${version["roomVersion"]}",
            "roomCompiler"             : "android.arch.persistence.room:compiler:${version["roomVersion"]}",
            "roomRxjava2"              : "android.arch.persistence.room:rxjava2:${version["roomVersion"]}",

            //Glide
            "glide"                    : "com.github.bumptech.glide:glide:${version["glideSdkVersion"]}",
            "glideCompiler"            : "com.github.bumptech.glide:compiler:${version["glideSdkVersion"]}",
            "glideAnnotations"         : "com.android.support:support-annotations:28.0.0",

            //view
            "autolayout"               : "com.zhy:autolayout:1.4.5",
            "butterknife"              : "com.jakewharton:butterknife:${version["butterknifeSdkVersion"]}",
            "butterknifeCompiler"      : "com.jakewharton:butterknife-compiler:${version["butterknifeSdkVersion"]}",
            "recyclerview"             : "androidx.recyclerview:recyclerview:${androidxVersion["recycleviewVersion"]}",

            "qmui"                     : "com.qmuiteam:qmui:2.0.0-alpha08",
            "qmuiteamArch"             : "com.qmuiteam:arch:2.0.0-alpha08",
            "bottomnavigationviewex"   : "com.github.ittianyu:BottomNavigationViewEx:2.0.2",
            "banner"                   : "com.youth.banner:banner:2.0.10",
            "magicindicator"           : "com.github.hackware1993:MagicIndicator:1.5.0",
            "sneaker"                  : "com.irozon.sneaker:sneaker:2.0.0",
            "imagePicker"              : "com.cysion:ImagePicker:1.0.7.x",
            "ninegridview"             : "com.lzy.widget:ninegridview:0.2.0",
            "pickView"                 : "com.contrarywind:Android-PickerView:4.1.8",
            "dialogsMaterial"          : "com.afollestad.material-dialogs:core:3.1.0",
            "dialogsPlus"              : "com.orhanobut:dialogplus:1.11@aar",
            "flowLayou"                : "com.hyman:flowlayout-lib:1.1.2",

            "rxlifecycle"              : "com.trello:rxlifecycle:${version["rxlifecycleSdkVersion"]}",
            "rxlifecycleComponents"    : "com.trello:rxlifecycle-components:${version["rxlifecycleSdkVersion"]}",
            "rxcache"                  : "com.github.VictorAlbertos.RxCache:runtime:1.7.0-1.x",
            "rxcacheJolyglotGson"      : "com.github.VictorAlbertos.Jolyglot:gson:0.0.4",
            "rxpermissions"            : "com.tbruyelle.rxpermissions:rxpermissions:0.9.4@aar",
            "rxpermissions2"           : "com.github.tbruyelle:rxpermissions:0.11",

            //fragment
            "fragmentation"            : "me.yokeyword:fragmentationx:${version["fragmentationVersion"]}",
            "fragmentationCode"        : "me.yokeyword:fragmentationx-core:${version["fragmentationVersion"]}",
            "fragmentationSwipeback"   : "me.yokeyword:fragmentationx-swipeback:${version["fragmentationVersion"]}",

            "rxlifecycle2"             : "com.trello.rxlifecycle2:rxlifecycle:${version["rxlifecycle2SdkVersion"]}",
            "rxlifecycle2Android"      : "com.trello.rxlifecycle2:rxlifecycle-android:${version["rxlifecycle2SdkVersion"]}",
            "rxlifecycle2Components"   : "com.trello.rxlifecycle2:rxlifecycle-components:${version["rxlifecycle2SdkVersion"]}",
            "rxcache2"                 : "com.github.VictorAlbertos.RxCache:runtime:1.8.3-2.x",
            "rxerrorhandler2"          : "me.jessyan:rxerrorhandler:2.1.1",

            //tools
            "dagger2"                  : "com.google.dagger:dagger:${version["dagger2SdkVersion"]}",
            "dagger2Android"           : "com.google.dagger:dagger-android:${version["dagger2SdkVersion"]}",
            "dagger2AndroidSupport"    : "com.google.dagger:dagger-android-support:${version["dagger2SdkVersion"]}",
            "dagger2Compiler"          : "com.google.dagger:dagger-compiler:${version["dagger2SdkVersion"]}",
            "dagger2AndroidProcessor"  : "com.google.dagger:dagger-android-processor:${version["dagger2SdkVersion"]}",
            "androideventbus"          : "org.simple:androideventbus:1.0.5.1",
            "liveEventBus"             : "io.github.jeremyliao:live-event-bus-x:1.8.0",
            "eventbus"                 : "org.greenrobot:eventbus:3.1.1",

            //加载webview
            "agentWebCore"             : "com.github.Justson.AgentWeb:agentweb-core:v5.0.6-androidx",
            "agentWebFilechooser"      : "com.github.Justson.AgentWeb:agentweb-filechooser:v5.0.6-androidx",
            "agentWebDownloader"       :"com.github.Justson:Downloader:v5.0.4-androidx",

            //Gson
            "gson"                     : "com.google.code.gson:gson:2.8.5",
            //
            "multidex"                 : "com.android.support:multidex:1.0.3",
            "annotationJsr250"         : "javax.annotation:jsr250-api:1.0",
            //PDF
            "pdfView"                  : "com.github.mhiew:android-pdf-viewer:3.2.0-beta.1",
            //app升级
            "updateApp"                : "com.qianwen:update-app:3.5.2",
            //悬浮窗
            "floatingView"             : "com.imuxuan:floatingview:1.6",
            "immersionbar"             : "com.geyifeng.immersionbar:immersionbar:3.2.2",
            "autosize"                 : "me.jessyan:autosize:1.1.1",
            "androidAutoSize"          : "com.github.JessYanCoding:AndroidAutoSize:v1.2.1",
            //极光推送
            "jpush"                    : "cn.jiguang.sdk:jpush:3.3.4",
            "jcore"                    : "cn.jiguang.sdk:jcore:2.1.2",
            "greendao"                 : "org.greenrobot:greendao:3.2.2",
            //环信
            "j256"                     : "com.j256.ormlite:ormlite-android:5.0",
            "googleGms"                : "com.google.android.gms:play-services-base:11.4.0",
            "googleFirebase"           : "com.google.firebase:firebase-messaging:11.4.0",
            "parse"                    : "com.parse:parse-android:1.13.1",
            "hxSdk"                    : "com.hyphenate:hyphenate-sdk:3.6.1",
            "zbar"                     : 'cn.bingoogolapple:bga-qrcode-zbar:1.3.6',

            "baseRecyclerViewAdapter"   : "com.github.CymChad:BaseRecyclerViewAdapterHelper:${version["baseRecycleViewVersion"]}",
            "smartrefreshlayout"        : "com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-andx-4",
            //ARoute
            "arouter"                   : "com.alibaba:arouter-api:${version["arouterSDk"]}",
            "arouterCompiler"           : "com.alibaba:arouter-compiler:${version["arouterCompilerSdk"]}",
            //工具类
            "utilcode"                  : "com.blankj:utilcodex:1.31.1",
            //播放视频
            "GSYVideoPlayer"            : "com.github.CarGuo.GSYVideoPlayer:GSYVideoPlayer:v8.3.4-release-jitpack",
            //test
            "timber"                    : "com.jakewharton.timber:timber:4.7.1",
            "canaryDebug"               : "com.squareup.leakcanary:leakcanary-android:${version["canarySdkVersion"]}",
            "canaryRelease"             : "com.squareup.leakcanary:leakcanary-android-no-op:${version["canarySdkVersion"]}",
            "mmkv"                      : "com.tencent:mmkv:1.2.15",

    //navigation Java
             "navigationFragment"    : "androidx.navigation:navigation-fragment:${version["navVersion"]}",
              "navigationUI"         : "androidx.navigation:navigation-ui:${version["navVersion"]}",

      //navigation Kotlin
              "navigationFragmentKt"    : "androidx.navigation:navigation-fragment-ktx:${version["navVersion"]}",
              "navigationUIKt"            : "androidx.navigation:navigation-ui-ktx:${version["navVersion"]}"
    ]
}

2、在项目的根目录的build.gradle中写入配置信息

apply from: "config.gradle"

3、在项目的build.gradle 中写入配置信息

plugins {
    id 'com.android.application'
}

android {
    compileSdk rootProject.ext.android.compileSdkVersion

    defaultConfig {
        applicationId   rootProject.ext.android.applicationId
        minSdk          rootProject.ext.android.minSdkVersion
        targetSdk       rootProject.ext.android.compileSdkVersion
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    dataBinding {
        enabled = true
    }

    //配置自定义打包名称
    applicationVariants.all { variant ->
        variant.outputs.all {
            def fileName
            if (variant.buildType.name.equals('release')) {
                fileName = "GongShi_${variant.mergedFlavor.versionName}_${variant.mergedFlavor.versionCode}.apk"
            } else if (variant.buildType.name.equals('debug')) {
                fileName = "GongShi_${variant.mergedFlavor.versionName}_debug_${variant.mergedFlavor.versionCode}.apk"
            }
            outputFileName = fileName
        }
    }
}

dependencies {

    implementation rootProject.ext.dependencies.appcompat
    implementation rootProject.ext.dependencies.material
    implementation rootProject.ext.dependencies.constraintlayout
    testImplementation rootProject.ext.dependencies.junit
    androidTestImplementation rootProject.ext.dependencies.testJunit
    androidTestImplementation rootProject.ext.dependencies.testEspresso

    implementation rootProject.ext.dependencies.rxjava2
    implementation rootProject.ext.dependencies.rxandroid2

    implementation rootProject.ext.dependencies.retrofit
    implementation rootProject.ext.dependencies.retrofitConverterGson
    implementation rootProject.ext.dependencies.retrofitAdapterRxjava2

    implementation rootProject.ext.dependencies.okhttp3
    implementation rootProject.ext.dependencies.okhttp3LoggingInterceptor

    implementation rootProject.ext.dependencies.pdfView
    implementation rootProject.ext.dependencies.rxpermissions2

    implementation rootProject.ext.dependencies.roomRuntime
    implementation rootProject.ext.dependencies.roomCompiler
    implementation rootProject.ext.dependencies.roomRxjava2

    implementation rootProject.ext.dependencies.glide
    implementation rootProject.ext.dependencies.updateApp

    implementation rootProject.ext.dependencies.floatingView

    implementation rootProject.ext.dependencies.immersionbar

    implementation rootProject.ext.dependencies.androidAutoSize

    implementation rootProject.ext.dependencies.baseRecyclerViewAdapter

    implementation rootProject.ext.dependencies.GSYVideoPlayer

}

最后重构这个项目即可。

参考于:

https://blog.csdn.net/qq_41326257/article/details/108099424

https://blog.csdn.net/songdongpanCSDN/article/details/79629568

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android 构建配置文件(config.gradle) 的相关文章

随机推荐

  • 观察者模式和事件通知备忘

    观察者模式和事件通知备忘 MessageBus instance post Notify PARKIN in bytes 这种是仿照Android的EventBus 用new的一个实例对象根据path反射调用其中的方法处理逻辑 要修改为 r
  • 【JVM】如何通俗地讲解JVM各个组成部分和其基本功能?

    类加载器 ClassLoader 运行时数据区 Runtime Data Area 执行引擎 Execution Engine 本地库接口 Native Interface 组件的作用 首先通过类加载器 ClassLoader 会把 Jav
  • (服务计算)在centos上编写golang的库,并进行测试

    首先是在centos上按照老师给的教程安装golang的相关内容 安装成功后进行后面的操作 首先是创建了一个hello go的文件 然后执行结果如下 可知安装基本正确 然后编写第一个库 首先创建包路径 然后创建名为reverse go的文件
  • 图形学基础1

    坐标系相关 uv可能会影响局部坐标系 如果light图和brdf图做卷积的时候 局部坐标系保持一致很重要 如下图 tangent是从外部模型文件进行加载的 切线空间采样并转世界坐标系 spherical to cartesian in ta
  • unity配置.asset文件

    unity配置数据可以XML 可以JSON unity自带的 asset文件也可以哦 而且能配置的数据类型也比较多 这里说明一下怎么在unity中生成 asset文件 首先来个脚本 using System using System Col
  • 【华为OD机试真题 python】报文解压缩

    题目描述 为了提升数据传输的效率 会对传输的报文进行压缩处理 输入一个压缩后的报文 请返回它解压后的原始报文 压缩规则 n str 表示方括号内部的 str 正好重复 n 次 注意 n 为正整数 0 lt n lt 100 str只包含小写
  • Dockerfile 中 CMD 为什么要避免使用 sh -c

    CSDN 中文章不一定能及时更新 欢迎点击前往我的博客查看最新版本 许盛的博客 Dockerfile 中的 CMD 命令 有 exec form 和 shell form 两种形式 具体区别可以参考 Dockerfile 中 CMD 写法的
  • CDN加速与DDOS防御

    一 目的 实现国外节点的访问加速 分区域分线路加速 防御来自竞争对手的DDos恶意攻击 常见的延缓性CC攻击和致命的大流量攻击 针对以上的加速策略和两种攻击方式进行一些防御方案的简单介绍 二 CDN加速 利用第三方的DNS智能解析分区域分线
  • Git学习之LFS

    什么是Git LFS git是程序员开发程序不可或缺的工具 有效的使用git能够极大的加快程序人员的开发效率 在开发比较轻量化的代码时 开发的速度不会受到git上传下载速度的影响 但是随着系统的复杂度增加 代码中关联到的文件越来越多 其中二
  • BGP实验(路由反射器,联邦,路由优化)

    目录 1 IP地址的规划 2 拓扑结构的搭建 3 IP地址的配置 4 静态路由的配置 5 动态路由的配置 6 EBGP的配置 7 IBGP的配置 8 路由反射器的配置 宣告 9 重发布和路由优化 10 测试 实验要求 实验步骤 1 IP地址
  • Ubuntu中调整终端terminal显示的缓冲区大小

    step1 step2 step3
  • hadoop单机版部署

    1 下载hadoop wget no check certificate https mirrors bfsu edu cn apache hadoop common hadoop 3 3 1 hadoop 3 3 1 tar gz 2 解
  • WebSocket详解

    WebSocket WebSocket是一种协议 它允许在客户端和服务器之间建立持久连接 实现双向实时通信 传统的http请求是客户端向服务器发起请求 服务器响应请求 而WebSocket解决服务器无法给客户端发送信息的问题 与HTTP协议
  • 2019年中国在线酒店预订行业发展分析报告

    核心摘要 单体酒店连锁化加速 OYO横空出世 鲶鱼效应显现 2019年以来中国单体酒店连锁化趋势加速推进 传统酒店集团锦江国际 华住 首旅如家等为应对OYO带来的挑战 大力推进轻加盟 快速扩张门店数量 此外 单体酒店快速连锁化给OTA平台的
  • geoda空间自相关分析_【方法笔记4】Geoda空间计量1 空间自相关

    以黑龙江省为例 1 导入shp格式地图 打开目标地图 点击第二行第4个数据按钮可以查看地图数据变量 2 数据合并 即将研究的各地级市数据与导入地图 捆绑 首先找到地图数据中可以唯一表征每个地级市的变量 如 其次将个人研究变量与上述可对各地级
  • Kubernetes 存活、就绪和启动探针

    Kubernetes主要有三中探针 存活 Liveness 就绪 Readiness 和启动 Startup 探针 kubelet 使用存活探针来确定什么时候要重启容器 例如 存活探针可以探测到应用死锁 应用程序在运行 但是无法继续执行后面
  • auth.log 频繁出现Cron: pam_unix (cron:session): session opened/closed for user root by (uid=0)

    This is my week of playing around with mail servers and I have been keeping an eye on the logs on a regular basis I noti
  • 面试题:说说你对闭包的理解?

    闭包 一个函数和它的词法环境的引用捆绑在一起这样的组合就形成了闭包 比如一个函数A return出去了一个函数B 那么这个函数B可以在外部访问函数A内部的变量 此时在就形成了一个函数B的变量背包 A函数执行结束 这个变量也不会被销毁 并且这
  • gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting

    gzip stdin not in gzip format tar Child returned status 1 tar Error is not recoverable exiting now 可能是下载链接不是资源链接 而是页面
  • Android 构建配置文件(config.gradle)

    1 新建config gradle 在自己的项目根目录下一个文件夹下创建一个config gradle文件名的文件 和settings gradble同目录 把自己需要用到的库跟版本号写在dependencies 标签括号内 ext and