gradle相关配置

apply plugin: 'com.android.application'

class StringExtension {
    String string

    StringExtension(String string) { this.string = string }

    public void setString(String string) { this.string = string }

    public String getString() { return string }
}
android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    defaultConfig {
        applicationId "com.test.gradle"
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 17
        versionName "1.8.0"
        resConfigs "zh"
        multiDexEnabled true
    }

    buildTypes {
        debug {
            shrinkResources true  // 移除无用的resource文件, 有代码动态调用资源文件的不能用,否则会找不到相关资源的
            buildConfigField "boolean", "ISDEBUG", "true"  //通过BuildConfig.ISDEBUG 设置是否为debug模式,控制log输出
            manifestPlaceholders = [BAIDU_KEY: "Rwdyl82FEoMNGCo2ZaGq7c", CHANNEL_NAME: "debug", UM_KEY: "567a6059e55ac54b003059"] //debug模式采用debug的key
        }

        release {
            minifyEnabled true  //打开混淆
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            buildConfigField "boolean", "ISDEBUG", "false"
            manifestPlaceholders = [BAIDU_KEY: "U5jb5t7yipsOZOcAd1MTja"]

		//根据不同渠道重命名生成的文件
            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    def outputFile = output.outputFile
                    if (outputFile != null && outputFile.name.endsWith('.apk')) {
                        def fileName = defaultConfig.versionName.replace(".", "_") + "_" + variant.productFlavors[0].channel.string + '.apk'
                        output.outputFile = new File(outputFile.parent, fileName)
                    }
                }
            }
        }
    }
 
  

//所有的x86/x86_64/armeabi-v7a/arm64-v8a设备都支持armeabi架构的.so文件,因此似乎移除其他ABIs的.so文件是一个减少APK大小的好技巧。

//但事实上并不是:这不只影响到函数库的性能和兼容性。如x86设备能够很好的运行ARM类型函数库,但并不保证100%不发生crash

    splits {
    	abi {
enable true reset() //重置ABI列表为只包含一个空字符串(这可以实现,在与include一起使用来可以表示要使用哪一个ABI,而不是要忽略哪一些ABI) include 'armeabi' //为了减小体积,只打包了armeabi的库 } } //渠道配置 productFlavors { whenObjectAdded { flavor -> //为了输出中文渠道名,自定义了个变量 flavor.extensions.create( "channel", StringExtension, '') } _test99 { channel.string = "开发" buildConfigField "int", "SERVER_INDEX", "2" manifestPlaceholders = [ CHANNEL_NAME: "99", UM_KEY: "567a6059e0f5554b003059"] } _test { channel.string = "测试" buildConfigField "int", "SERVER_INDEX", "0" manifestPlaceholders = [ CHANNEL_NAME: "测试", UM_KEY: "567a6059e55ac54b003059"] } } lintOptions { checkReleaseBuilds false abortOnError false } dexOptions { incremental true javaMaxHeapSize "4g" }}dependencies { compile fileTree( include: [ '*.jar'], dir: 'libs')
    compile 'com.android.support:multidex:1.0.1'
}

你可能感兴趣的:(Android)