as将安卓应用打包_Android应用开发之as android 打包

本文详细介绍了如何在Android Studio中进行应用的打包过程,包括生成 Signed APK 的步骤,以及如何配置多渠道打包和签名设置。通过设置不同的manifestPlaceholders来实现渠道区分,并提供了debug和release两种模式的签名配置。此外,还提到了如何修改APK的输出文件名以区分不同版本和渠道。
摘要由CSDN通过智能技术生成

本文将带你了解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频道!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值