本文将带你了解Android应用开发之as android 打包,希望本文对大家学Android有所帮助
1. build -> Generate Signed APK
2. next -》 next
3. 多渠道打包
Java代码
android:name="UMENG_CHANNEL"
android:value="${UMENG_CHANNEL_VALUE}" />
Java代码 signingConfigs { debug { keyAlias 'curiousby' keyPassword '123456' storeFile file('C:\\Users\\cmcc-B100036\\Desktop\\android\\iteyeblog-as\\iteyeblog-as.jks') storePassword '123456' } release { keyAlias 'curiousby' keyPassword '123456' storeFile file('C:\\Users\\cmcc-B100036\\Desktop\\android\\iteyeblog-as\\iteyeblog-as.jks') storePassword '123456' } } buildTypes { // 打测试包 debug{ // 显示Log buildConfigField "boolean", "DEBUG_ENABLE", "true" versionNameSuffix "-debug" minifyEnabled false zipAlignEnabled false shrinkResources false signingConfig signingConfigs.debug } // 打正式包 release { // 不显示Log buildConfigField "boolean", "DEBUG_ENABLE", "false" // 启用混淆 minifyEnabled false // Zipalign优化 zipAlignEnabled true // 移除无用的resource文件 shrinkResources false 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')) { // 输出apk名称为IteyeBlog_v1.0_2016-07-31_wandoujia.apk def fileName = "IteyeBlog_${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk" //_${releaseTime()} output.outputFile = new File(outputFile.parent, fileName) } } } } } // 配置渠道包 productFlavors { MAIN { manifestPlaceholders = [UMENG_CHANNEL_VALUE: "MAIN"] } WANDOUJIA { manifestPlaceholders = [UMENG_CHANNEL_VALUE: "WANDOUJIA"] } BAIDU { manifestPlaceholders = [UMENG_CHANNEL_VALUE: "BAIDU"] } QIHU360 { manifestPlaceholders = [UMENG_CHANNEL_VALUE: "QIHU360"] } XIAOMI { manifestPlaceholders = [UMENG_CHANNEL_VALUE: "XIAOMI"] } YINGYONGBAO { manifestPlaceholders = [UMENG_CHANNEL_VALUE: "YINGYONGBAO"] } } signingConfigs {
debug {
keyAlias 'curiousby'
keyPassword '123456'
storeFile file('C:\\Users\\cmcc-B100036\\Desktop\\android\\iteyeblog-as\\iteyeblog-as.jks')
storePassword '123456'
}
release {
keyAlias 'curiousby'
keyPassword '123456'
storeFile file('C:\\Users\\cmcc-B100036\\Desktop\\android\\iteyeblog-as\\iteyeblog-as.jks')
storePassword '123456'
}
}
buildTypes {
// 打测试包
debug{
// 显示Log
buildConfigField "boolean", "DEBUG_ENABLE", "true"
// versionNameSuffix "-debug"
minifyEnabled false
zipAlignEnabled false
shrinkResources false
signingConfig signingConfigs.debug
}
// 打正式包
release {
// 不显示Log
buildConfigField "boolean", "DEBUG_ENABLE", "false"
// 启用混淆
minifyEnabled false
// Zipalign优化
zipAlignEnabled true
// 移除无用的resource文件
shrinkResources false
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')) {
// 输出apk名称为IteyeBlog_v1.0_2016-07-31_wandoujia.apk
def fileName = "IteyeBlog_${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk" //_${releaseTime()}
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
}
// 配置渠道包
productFlavors {
MAIN {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "MAIN"]
}
WANDOUJIA {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "WANDOUJIA"]
}
BAIDU {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "BAIDU"]
}
QIHU360 {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "QIHU360"]
}
XIAOMI {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "XIAOMI"]
}
YINGYONGBAO {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "YINGYONGBAO"]
}
}
点击 task
4. 使用 eclipse 签名 打包
Java代码 signingConfigs { debug { keyAlias 'baoyou' keyPassword '123456' storeFile file('C:\\Users\\cmcc-B100036\\Desktop\\android\\android-cmcc-B100036') storePassword '123456' } release { keyAlias 'baoyou' keyPassword '123456' storeFile file('C:\\Users\\cmcc-B100036\\Desktop\\android\\android-cmcc-B100036') storePassword '123456' } } signingConfigs {
debug {
keyAlias 'baoyou'
keyPassword '123456'
storeFile file('C:\\Users\\cmcc-B100036\\Desktop\\android\\android-cmcc-B100036')
storePassword '123456'
}
release {
keyAlias 'baoyou'
keyPassword '123456'
storeFile file('C:\\Users\\cmcc-B100036\\Desktop\\android\\android-cmcc-B100036')
storePassword '123456'
}
}
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之Android频道!