3张图片让你彻底明白app目录下build.gradle中配置的用法和含义

as中的app目录下通常要配置一大堆东西,好多东西莫名又费解,这里参考几个博客内容整理了一下,都有注释,希望大家能一起理解,满满的干货。
直接上图:
这里写图片描述
这里写图片描述
这里写图片描述

看完上面图片后,应该对很多配置都知晓到底是做什么用的了….

下面上配置代码:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24 //最高API等级
    buildToolsVersion "25.0.0" //buildtools的版本号
    defaultConfig {  //默认配置
        applicationId "com.example.user.launchmode" //应用id,相当于包名
        minSdkVersion 17 //最小API等级
        targetSdkVersion 24//编译API等级
        versionCode 1//版本号
        versionName "1.0"//版本名称
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" //单元测试

       /**dex突破65535的限制*/
        multiDexEnabled true
        /**这里用到UMENG 多渠道打包*/
        manifestPlaceholders=[UMENG_CHANNEL_VALUE: "channel_name"]
    }

    /**执行lint检查,有任何的错误或者警告提示,都会终止构建,可以关闭*/
    lintOptions{
        abortOnError false
    }

   /**签名配置*/
    signingConfigs{
        debug{
            /**app keystore路劲*/
            storeFile file("../yourapp.keystore")
        }

        release{
            storeFile file("../yourapp.keystore")
            /**打包签名时在build里面的key store password*/
            storePassword "123456"
            /**打包签名时,build里面的keyAlias*/
            keyAlias "launch"
            /**打包签名时,build里面的key password*/
            keyPassword "123456"
        }
    }
    buildTypes { //构建类型
        release { //正式版配置
            /**是否开启混淆 true表示开启*/
            minifyEnabled true
            /**是否删除无效Resource true表示删除*/
            shrinkResources true
            /**不显示Log*/
            buildConfigFields "boolean","LOG_DEBUG","false"
            /**Zipalign优化*/
            zipAlignEnabled true
            /**混淆配置文件 和minifyEnabled一起使用*/
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            /**签名*/
            signingConfig signingConfigs.release
        }

        debug{

            /** 和s上面release设置一样*/
        }
    }

    /**友盟多渠道打包设置*/
    productFlavors{
        xiaomi{}
        _360{}
        baidu{}
        wandoujia{}
    }

    /**和上面多渠道打包配合使用的,这是一种简写方法*/
    productFlavors.all{
        flavor ->flavor.manifestPlaceholders=[UMENG_CHANNEL_VALUE:name]
    }

}

/**依赖配置*/
dependencies {
    /**依赖本地二进制*/
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    /**依赖远程二进制*/
    compile 'com.android.support:appcompat-v7:24.2.1'
    testCompile 'junit:junit:4.12'
    /** 依赖的moudle名称*/
    compile project(':moudle名称')
}

一起努力,多分享干货文章,加油…….

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值