eclipse中gradle 打包配置
| buildscript { | |
| repositories { | |
| mavenCentral() | |
| } | |
| dependencies { | |
| classpath 'com.android.tools.build:gradle:1.0.+' | |
| } | |
| } | |
| apply plugin: 'android' | |
| dependencies { | |
| compile fileTree(dir: 'libs', include: ['*.jar']) | |
| compile 'com.android.support:support-v4:+' | |
| //下面的是添加Eclipse的依赖工程 | |
| compile project(':HorizontalVariableListView-master') | |
| compile project(':ListView_animotion/library') | |
| compile project(':MultiprocessPreferences-master') | |
| compile project(':PinterestLikeAdapterView-master') | |
| } | |
| android { | |
| compileSdkVersion 19 | |
| buildToolsVersion "19.1.0" | |
| packagingOptions { | |
| exclude 'META-INF/DEPENDENCIES' | |
| exclude 'META-INF/notice.txt' | |
| exclude 'META-INF/LICENSE.txt' | |
| exclude 'META-INF/MANIFEST.MF' | |
| exclude 'META-INF/LICENSE' | |
| exclude 'META-INF/NOTICE' | |
| } | |
| defaultConfig { | |
| minSdkVersion 10 | |
| targetSdkVersion 20 | |
| } | |
| sourceSets { | |
| main { | |
| manifest.srcFile 'AndroidManifest.xml' | |
| java.srcDirs = ['src'] | |
| resources.srcDirs = ['src'] | |
| aidl.srcDirs = ['src'] | |
| renderscript.srcDirs = ['src'] | |
| res.srcDirs = ['res'] | |
| assets.srcDirs = ['assets'] | |
| //下面选项是添加对native libs的编译支持 | |
| jniLibs.srcDirs = ['libs'] | |
| } | |
| } | |
| lintOptions { | |
| abortOnError false | |
| checkReleaseBuilds false | |
| } | |
| signingConfigs { | |
| release { | |
| //输入自己的keyStore以及keyAlias | |
| storeFile file("release.keystore") | |
| storePassword STOREPASS | |
| keyAlias 'xxxx' | |
| keyPassword KEYPASS | |
| } | |
| } | |
| buildTypes { | |
| release { | |
| signingConfig signingConfigs.release | |
| minifyEnabled true | |
| zipAlignEnabled true | |
| //输入自己的混淆文件 | |
| proguardFile 'proguard.txt' | |
| } | |
| } | |
| productFlavors { | |
| // Main android app markets | |
| Mocha{} | |
| Xiaomi{} | |
| //添加pre是因为flavor命名不支持数字开头,编译的时候会做处理 | |
| pre360Channel{} | |
| Baidu{} | |
| Hiapk{} | |
| pre91Channel{} | |
| WanDouJia{} | |
| Tencent{} | |
| Anzhi{} | |
| AppChina{} | |
| } | |
| } | |
| tasks.withType(JavaCompile) { | |
| options.encoding = "UTF-8" | |
| } | |
| import java.util.regex.Pattern | |
| import java.util.regex.Matcher | |
| //替换AndroidManifest.xml的UMENG_CHANNEL_VALUE字符串为渠道名称 By Remex Huang | |
| android.applicationVariants.all{ variant -> | |
| variant.outputs.get(0).processManifest.doLast{ | |
| //之前这里用的copy{},我换成了文件操作,这样可以在v1.11版本正常运行,并保持文件夹整洁 | |
| //${buildDir}是指./build文件夹 | |
| //${variant.dirName}是flavor/buildtype,例如GooglePlay/release,运行时会自动生成 | |
| //下面的路径是类似这样:./build/manifests/GooglePlay/release/AndroidManifest.xml | |
| def channel; | |
| def apkname = ""; | |
| if(variant.productFlavors[0].name.contains("_")){ | |
| def flavorNames = variant.productFlavors[0].name.split("_") | |
| channel = flavorNames[0] | |
| apkname = "_" + flavorNames[1] | |
| } else { | |
| channel = variant.productFlavors[0].name | |
| if(!channel.contains("Mocha")){ | |
| apkname = "_" + channel | |
| } | |
| } | |
| channel = channel.replaceAll("pre", "") | |
| apkname = apkname.replaceAll("pre", "") | |
| def manifestFile = "${buildDir}/intermediates/manifests/full/${variant.dirName}/AndroidManifest.xml" | |
| //将字符串UMENG_CHANNEL_VALUE替换成flavor的名字 | |
| def updatedContent = new File(manifestFile).getText('UTF-8').replaceAll("MOCHA_CHANNEL", channel) | |
| new File(manifestFile).write(updatedContent, 'UTF-8') | |
| //获取版本号 | |
| def patternVersionNumber = Pattern.compile("versionName=\"(\\d+)\\.(\\d+)\\.(\\d+)\"") | |
| def manifestText = new File(manifestFile).getText() | |
| def matcherVersionNumber = patternVersionNumber.matcher(manifestText) | |
| matcherVersionNumber.find() | |
| def majorVersion = Integer.parseInt(matcherVersionNumber.group(1)) | |
| def minorVersion = Integer.parseInt(matcherVersionNumber.group(2)) | |
| def pointVersion = Integer.parseInt(matcherVersionNumber.group(3)) | |
| def versionName = + majorVersion + "." + minorVersion + "." + pointVersion | |
| //将此次flavor的AndroidManifest.xml文件指定为我们修改过的这个文件 | |
| variant.outputs.get(0).processResources.manifestFile = file("${buildDir}/intermediates/manifests/full/${variant.dirName}/AndroidManifest.xml") | |
| println "******************/\n/\n/\n/\n/\n/\n" | |
| println "buildType.name = " + variant.buildType.name | |
| println "******************/\n/\n/\n/\n/\n/\n" | |
| def apkName = "Mocha"; | |
| if (variant.buildType.name == "release") { | |
| apkName += apkname + "_V" + versionName + ".apk"; | |
| //variant.outputFile = file("${buildDir}/outputs/mochapk/" + apkName) | |
| // !! 这里需要自定义自己的输出文件夹 | |
| variant.outputs.get(0).outputFile = file("/Users/tengfei/Documents/yunyao/code/mocha/apk/" + versionName + "/" + apkName) | |
| } else { | |
| apkName += apkname + "-SNAPSHOT.apk"; | |
| variant.outputs.get(0).outputFile = file("${buildDir}/outputs/apk/" + apkName) | |
| } | |
| } | |
| } |
posted on 2015-06-11 14:31 Amber_chan 阅读(4182) 评论(0) 收藏 举报
浙公网安备 33010602011771号