1、gradle文件的详细配置信息 buildscript { //表示当前程序类型为Android apply plugin: 'com.android.application' //仓库 repositories { jcenter() } } //告诉gradle构建时用utf-8进行编码 tasks.withType(JavaCompile) { options.encoding = "UTF-8" } //获取当前日期 def releaseTime() { return new Date().format("yyyyMMddHHmm", TimeZone.getTimeZone("GMT+8")) } //配置Java的版本为1.7 compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } android { signingConfigs { debug { // 作用是只使用旧版签名,禁用V2版签名模式 v2SigningEnabled true } release { // 作用是只使用旧版签名,禁用V2版签名模式 v2SigningEnabled true } } buildTypes { debug { //多余的参数 minifyEnabled true//是否进行混淆 zipAlignEnabled true//代码压缩 shrinkResources false//解决无效字符的问题 移除无用的resource文件 signingConfig signingConfigs.debug } //release版本的配置 release { minifyEnabled true//是否进行混淆 zipAlignEnabled true//代码压缩 shrinkResources false//资源压缩 移除无用的resource文件 signingConfig signingConfigs.debug //resConfigs "en", "fr" //代表仅支持英语和法语 //采用动态形式替换字符串的方式生成不同的.apk applicationVariants.all { variant -> variant.outputs.each { output -> def outputFile = output.outputFile if (outputFile != null && outputFile.name.endsWith('.apk')) { // 输出apk名称为xxx1.0@wandoujia.apk def fileName = "xxx${defaultConfig.versionName}@${variant.productFlavors[0].name}.apk" //Build${releaseTime()} output.outputFile = new File(outputFile.parent, fileName) } } } } } productFlavors { //不同渠道 official {} } //为每个渠道包产生不同的 UMENG_CHANNEL_VALUE 的值。 productFlavors.all { flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] } //编译sdk的版本,也就是API Level, compileSdkVersion 25 //build tools的版本,其中包括了打包工具aapt、dx等等 buildToolsVersion '25.0.2' aaptOptions { //防止该问题的出现 //if true 1.The aapt tool may inflate PNG files that have already been compressed //2.does not shrink PNG files contained in the asset/ folder. cruncherEnabled = false useNewCruncher = false } //默认的一些文件路径的配置 sourceSets { main { jniLibs.srcDirs = ['libs'] manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] resources.srcDirs = ['src'] aidl.srcDirs = ['src'] renderscript.srcDirs = ['src'] res.srcDirs = ['res'] //资源文件 assets.srcDirs = ['assets'] } debug.setRoot('build-types/debug') release.setRoot('build-types/release') } defaultConfig { //应用包名 applicationId 'com.chemayi.manager' //更新版本号 versionCode 38 //版本信息 versionName '4.2' //最小sdk版本 minSdkVersion 14 目标sdk版本 targetSdkVersion 20 // dex突破65535的限制 multiDexEnabled true signingConfig signingConfigs.debug } dexOptions { maxProcessCount 4 //最大进程个数 javaMaxHeapSize "4g" //增加java堆内存大小 preDexLibraries = false //增高Android Studio的gradle编译速度 jumboMode = false } //设置忽略文件 packagingOptions { exclude '' } lintOptions { //checkReleaseBuilds就是在打包Release版本的时候进行检测错误 abortOnError false } } dependencies { //添加依赖 }
gradle的配置信息详解
最新推荐文章于 2024-05-10 18:57:51 发布