buildToolsVersion "23.0.3"
引入第三方so库时需要配置sourceSets
}
配置包名版本等
defaultConfig {
applicationId "com.packname"
minSdkVersion 14
targetSdkVersion 17
versionCode 1
versionName "1.0.0"
// dex突破65535的限制
multiDexEnabled true
// 默认是umeng的渠道
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "umeng"]
}
自动签名打包
signingConfigs {
debug {
keyAlias '。。。'
keyPassword 'passwd'
storePassword 'passwd'
storeFile file('项目keystore')
}
release {
keyAlias '...'
keyPassword 'passwd'
storePassword '1passwd'
storeFile file('项目keystore.jks')
}
}
构建类型,分debug、release
buildTypes {
debug {
// 显示Log
buildConfigField "boolean", "LOG_DEBUG", "true"
buildConfigField "boolean", "API_ENV", "true"
buildConfigField "String", "API_SERVER_URL", "\"http://test...\""
buildConfigField "String", "API_WEB_URL","\"http://test...\""
buildConfigField "String", "API_3G_URL","\"http://www...\""
buildConfigField "String", "IMAGE_TYPE", "\".jpg,.png,.gif\""
versionNameSuffix "-debug"
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
debuggable true
}
release {
// 不显示Log
buildConfigField "boolean", "LOG_DEBUG", "false"
buildConfigField "boolean", "API_ENV", "false"
buildConfigField "String", "API_SERVER_URL", "\"http://apps...""
buildConfigField "String", "API_3G_URL","\"http://www...""
buildConfigField "String", "API_WEB_URL","\"http://apps...\""
buildConfigField "String", "IMAGE_TYPE", "\".jpg,.png,.gif\""
debuggable false
minifyEnabled //使用混淆
zipAlignEnabled true
// 移除无用的resource文件
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
def fileName = "v${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
}
多渠道打包
productFlavors {
baidu {}
_360 {}
wandoujia {}
yingyongbao{}
yingyonghui{}
jifeng{}
lenovo{}
yidong{}
huawei{}
xiaomi {}
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.squareup.picasso:picasso:2.5.2'
//.aar文件
compile name: ' 文件name', ext: 'aar'
}