为了账号安全,请及时绑定邮箱和手机立即绑定

5. gradle配置模板

标签:
Android

如果没看懂,可以先看上面几篇文章:


webp

2.png


主要文件如上图:
注意:以下第1、2、 3点是配置信息,第4是寻找配置的文件,第5是最终引用


1. app目录下的sign.gradle(test.jks 签名信息)
ext {    //签名信息
    STORE_FILE = "test.jks"
    STORE_PASSWORD = "123456"
    KEY_ALIAS = "123456"
    KEY_PASSWORD = "123456"}
2.项目根目录下config包下app.gradle (App主要配置信息)
ext {    //sdk版本管理
    COMPILE_SDK_VERSION = 26  // 用于编译的SDK版本
    BUILD_TOOLS_VERSION = "28.0.3" // 用于Gradle编译项目的工具版本

    APPLICATION_ID = "com.liys.gradleconfig" //包名
    MIN_SDK_VERSION = 19    // 最低支持Android版本
    TARGET_SDK_VERSION = 26   // 目标版本
    VERSION_CODE = 1         //版本号
    VERSION_NAME = "1.0"
    MINIFY_ENABLED = false //是否混淆

    //日志管理
    LOG_DEBUG_TYPE = "boolean" //是否输出日志 变量类型
    LOG_DEBUG_NANE = "LOG_DEBUG" //是否输出日志 变量名
    LOG_DEBUG_DEBUG = "true"  //是否输出日志(debug版)
    LOG_DEBUG_RELEASE = "false" //是否输出日志(正式版)

    //baseUrl地址
    BASE_URL_TYPE = "String" //返回值
    BASE_URL_NAME = "BASE_URL" //变量名
    BASE_URL_RELEASE = "\"http:\"" //线上地址
    BASE_URL_DEBUG = "\"http:\"" // 本地地址

    // App dependencies
    appcompatVersion = "26.1.0"
    constraintVersion = "1.1.3"
    junitVersion = "4.12"
    runnerVersion = "1.0.2"
    espressoVersion = "3.0.2"

    //公共的(系统的)
    roots = [            //项目基本的(每个项目需要的)
            "appcompatV7"               :   "com.android.support:appcompat-v7:${appcompatVersion}",            "constraint"                :   "com.android.support.constraint:constraint-layout:${constraintVersion}",            "junit"                     :   "junit:junit:${junitVersion}",            "runner"                    :   "com.android.support.test:runner:${runnerVersion}",            "espresso"                  :   "com.android.support.test.espresso:espresso-core:${espressoVersion}",

    ]    //第三方框架
    thirdFrame = [            "gson"                      :"com.google.code.gson:gson:2.8.0", //gson解析
            "glide"                     :"com.github.bumptech.glide:glide:3.7.0", //glide

    ]    //App需要导入的包
    app = [
            thirdFrame.gson,
            thirdFrame.glide,
    ]
}
3.项目根目录下config包下source.gradle (资源分包目录)
ext{    //res资源文件
    resSource = [            'src/main/res',            'src/main/res-main/home',
    ]
}
4.项目根目录下build.gradle,尾部加上:
apply from: 'config/app.gradle'apply from: 'config/source.gradle'
5.app目录下build.gradle
apply plugin: 'com.android.application'apply from: 'sign.gradle'android {    //SDK和App版本
    compileSdkVersion COMPILE_SDK_VERSION
    defaultConfig {
        applicationId APPLICATION_ID
        minSdkVersion MIN_SDK_VERSION
        targetSdkVersion TARGET_SDK_VERSION
        versionCode VERSION_CODE
        versionName VERSION_NAME
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }    //签名
    signingConfigs{
        release {            storeFile file(STORE_FILE)
            storePassword STORE_PASSWORD
            keyAlias KEY_ALIAS
            keyPassword KEY_PASSWORD
        }
        debug {
            release
        }
    }    //混淆和日志
    buildTypes {
        release {            minifyEnabled MINIFY_ENABLED
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField LOG_DEBUG_TYPE, LOG_DEBUG_NANE, LOG_DEBUG_RELEASE //是否输出LOG信息
            buildConfigField BASE_URL_TYPE, BASE_URL_NAME, BASE_URL_RELEASE // baseUrl
            signingConfigs.release
        }
        debug{
            buildConfigField LOG_DEBUG_TYPE, LOG_DEBUG_NANE, LOG_DEBUG_DEBUG //是否输出LOG信息
            buildConfigField BASE_URL_TYPE, BASE_URL_NAME, BASE_URL_DEBUG //baseUrl
        }
    }    //资源分包
    sourceSets{
        main {
            res.srcDirs = [ resSource.each{it} ]
        }
    }
}

dependencies {    //系统的
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation roots.appcompatV7
    implementation roots.constraint
    testImplementation roots.junit
    androidTestImplementation roots.runner
    androidTestImplementation roots.espresso    //导入第三方框架
    app.each {
        implementation it
    }    //依赖库
    implementation project(':testlibrary')}



作者:liys_android
链接:https://www.jianshu.com/p/14ab90613877


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消