您的位置:首页 > 移动开发 > Android开发

android 批量打包

2016-04-26 16:41 447 查看
由于公司有一百多个渠道,需要一百多个包,使用eclipse打包,不用说大家就知道我的感受了,一个人3天什么事也不做,关键是这活一点技术含量也没有,没意思,实在没办法批量打包吧!

1 工具intellij idea

2 把原来的代码转移至idea项目中,删除多余的代码

3 编译,如果图片出错,用工具转一下(ImageMagick Display)

4 配置资源

gradle 文件:

buildscript {

repositories {

mavenCentral()

}

dependencies {

classpath ‘com.android.tools.build:gradle:1.3.1’

}

}

apply plugin: ‘com.android.application’

repositories {

mavenCentral()

mavenLocal()

flatDir {

dirs ‘libs’

}

maven {

url “https://oss.sonatype.org/content/repositories/snapshots/

}

}

android {

compileSdkVersion 23

buildToolsVersion “23.0.2”

productFlavors {

xxxxx1{
manifestPlaceholders = [ CHANNEL_NAME:"com.xxx.xxx"]
applicationId "com.xxx.xxx"
}
xxxxx2 {
manifestPlaceholders = [ CHANNEL_NAME:"com.xxx.xxx"]
applicationId "com.xxx.xxx"
}
xxxxx3 {
manifestPlaceholders = [ CHANNEL_NAME:"com.xxx.xxx"]
applicationId "com.xxx.xxx"
}
xxxxx4{
manifestPlaceholders = [ CHANNEL_NAME:"com.xxx.xxx"]
applicationId "com.xxx.xxx"
}
xxxxx5{
manifestPlaceholders = [ CHANNEL_NAME:"com.xxx.xxx"]
applicationId "com.xxx.xxx"
}
xxxxx6 {
manifestPlaceholders = [ CHANNEL_NAME:"com.xxx.xxx"]
applicationId "com.xxx.xxx"
}

xxxxx7{
manifestPlaceholders = [ CHANNEL_NAME:"com.xxx.xxx"]
applicationId "com.xxx.xxx"
}

}
lintOptions {
abortOnError false
}

defaultConfig {
applicationId "com.xxx.xxx"
minSdkVersion 14
targetSdkVersion 22
versionCode 30
versionName "3.2.0"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

//打包签名
signingConfigs {
myConfig {

storeFile file("xxx.keystore")
storePassword "xxx"
keyAlias "xxx"
keyPassword "xxx"
}
}
buildTypes {
release {
signingConfig signingConfigs.myConfig
minifyEnabled true
zipAlignEnabled true
proguardFiles 'proguard-rules.pro'
}

}


}

dependencies {

compile fileTree(dir: ‘libs’, include: [‘*.jar’])

}

def product_name = “v” + android.defaultConfig.versionName

def time = “3000”

task initTimeScape << {

println “first time”

println “time”defgCalendar=newGregorianCalendar()time=gCalendar.time.format(“MMddHHmm”)println“secondtime”println“time”
def gCalendar = new GregorianCalendar()
time = gCalendar.time.format(“MMddHHmm”)
println “second time”
println “time”

}

task initReleaseApkProduct_name(dependsOn: [‘initTimeScape’]) << {

//初始化release包名

product_name = product_name + “_” + time + “R.apk”

def outputName = “OUT:>PRODUCT_FILENAME=” + product_name + “;”

println “$outputName”

}

task initDebugApkProduct_name(dependsOn: [‘initTimeScape’]) << { //初始化release包名

product_name = product_name + “_” + time + “D.apk”

def outputName = “OUT:>PRODUCT_FILENAME=” + product_name + “;”

println “$outputName”

}

task release(dependsOn: [‘assembleRelease’, ‘initReleaseApkProduct_name’]) << {

copy {

from(‘build/outputs/apk’) {

include(‘*/-release.apk’)

rename ‘(.*)-release.apk’, product_name

}

from(‘build/proguard/release’) {

include(‘**/mapping.txt’)

rename ‘(.*).txt’, product_name + “.map”

}

into(‘products’)

}

}

task debug(dependsOn: [‘assembleDebug’, ‘initDebugApkProduct_name’]) << {

copy {

from(‘build/outputs/apk’) {

include(‘*/.apk’)

rename ‘(.*).apk’, product_name

}

into(‘products’)

}

}

资源配置:

src下和main同目录,创建包,抽取不同的资源,特别注意向,对于自定义的view,命名空间需要改一下。

clean —> release
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: