转自: http://www.eoeandroid.com/thread-325377-1-1.html
在用过maven,ant等项目等工具后后,发现觉得Android最佳的项目管理以及打包实践:Git/SVN+Jenkins+Gradle Gradle 脚本: [mw_shl_code=java,true]import com.android.builder.DefaultManifestParser buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.5.6'//依赖 } } apply plugin: 'android' dependencies { compile fileTree(dir: 'libs', include: '*.jar')//添加android依赖libs } android { compileSdkVersion 19 buildToolsVersion "19.0.0" //签名 signingConfigs { myConfig { storeFile file('ext/test.keystore') storePassword '123456' keyAlias '123456' keyPassword '123456' } } defaultConfig { versionCode 1 versionName getVersionName() minSdkVersion 8 targetSdkVersion 19 debuggable=false; } //渠道 productFlavors { google{ } tantai{ } } buildTypes{ release { signingConfig signingConfigs.myConfig runProguard true proguardFile 'proguard.cfg' } } sourceSets { main { manifest { srcFile 'AndroidManifest.xml' } java { srcDir 'src' } res { srcDir 'res' } assets { srcDir 'assets' } resources { srcDir 'src' } aidl { srcDir 'src' } } } } tasks.withType(Compile) { //options.encoding = "UTF-8" } //替换AndroidManifest.xml的UMENG_CHANNEL_VALUE字符串为渠道名称 android.applicationVariants.all{ variant -> variant.processManifest.doLast{ copy{ from("${buildDir}/manifests"){ include "${variant.dirName}/AndroidManifest.xml" } into("${buildDir}/manifests/$variant.name") filter{ String line -> line.replaceAll("UMENG_CHANNEL_VALUE", "$variant.name") } variant.processResources.manifestFile = file("${buildDir}/manifests/${variant.name}/${variant.dirName}/AndroidManifest.xml") } } def manifestParser = new DefaultManifestParser() def version =manifestParser.getVersionName(android.sourceSets.main.manifest.srcFile) //def versionName = android.defaultConfig.versionName //def versionNameSuffix = variant.buildType.versionNameSuffix //if(versionNameSuffix.toString().equals("null")){ //versionNameSuffix = "" //} //def version= versionName+versionNameSuffix; def apk = variant.packageApplication.outputFile; println version; def newName = version+"//"+"unaligned//"+apk.name.replace(".apk","-"+version+".apk"); newName=newName.replace("release","release(proguard)"); variant.packageApplication.outputFile = new File(apk.parentFile, newName); if (variant.zipAlign) { newName=newName.replace("unaligned//", ""); variant.zipAlign.outputFile = new File(apk.parentFile, newName.replace("-unaligned", "")); } //delete new File(apk.parentFile, "unaligned"); }[/mw_shl_code] |