多渠道打包

# android多渠道打包 #

## 1.如何查看apk的签名信息  ##

1将apk解压;

2.找到META-INF 下的.RSA文件;

3.进入cmd环境,进入.RSA文件文件所在路径,命令:keytool -printcert -file XXX.RSA即可查看签名信息。

查看Android开发的数字签名信息:

1.cmd环境下进入C:\Users\用户名\.android目录下;

2.keytool -list -v -keystore debug.keystore;

![](https://github.com/zxp0505/ManagerSummary/blob/master/image/1.png)

debug.keystore

![](https://github.com/zxp0505/ManagerSummary/blob/master/image/2.png)

![](image/2.png)

## 友盟的打包方案(常见) ##:

http://stormzhang.com/devtools/2015/01/15/android-studio-tutorial6/

友盟统计多渠道为例:

1.在AndroidManifest.xml中配置placeholder

android:name="UMENG_CHANNEL"

android:value="${UMENG_CHANNEL_VALUE}" />

2.在build.gradle中设置productFlavors

android {

productFlavors {

xiaomi {

manifestPlaceholders = [UMENG_CHANNEL_VALUE: "xiaomi"]

}

_360 {

manifestPlaceholders = [UMENG_CHANNEL_VALUE: "_360"]

}

baidu {

manifestPlaceholders = [UMENG_CHANNEL_VALUE: "baidu"]

}

wandoujia {

manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]

}

}

}

或者批量修改

android {

productFlavors {

xiaomi {}

_360 {}

baidu {}

wandoujia {}

}

productFlavors.all {

flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]

}

}

直接执行 gradle assembleRelease 慢慢等待打包完成

完整gradle 脚本

apply plugin: 'com.android.application'

def releaseTime() {

return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))

}

android {

compileSdkVersion 21

buildToolsVersion '21.1.2'

defaultConfig {

applicationId "com.boohee.*"

minSdkVersion 14

targetSdkVersion 21

versionCode 1

versionName "1.0"

// dex突破65535的限制

multiDexEnabled true

// 默认是umeng的渠道

manifestPlaceholders = [UMENG_CHANNEL_VALUE: "umeng"]

}

lintOptions {

abortOnError false

}

signingConfigs {

debug {

// No debug config

}

release {

storeFile file("../yourapp.keystore")

storePassword "your password"

keyAlias "your alias"

keyPassword "your password"

}

}

buildTypes {

debug {

// 显示Log

buildConfigField "boolean", "LOG_DEBUG", "true"

versionNameSuffix "-debug"

minifyEnabled false

zipAlignEnabled false

shrinkResources false

signingConfig signingConfigs.debug

}

release {

// 不显示Log

buildConfigField "boolean", "LOG_DEBUG", "false"

minifyEnabled true

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')) {

// 输出apk名称为boohee_v1.0_2015-01-15_wandoujia.apk

def fileName = "boohee_v${defaultConfig.versionName}_${releaseTime()}_${variant.productFlavors[0].name}.apk"

output.outputFile = new File(outputFile.parent, fileName)

}

}

}

}

}

// 友盟多渠道打包

productFlavors {

wandoujia {}

_360 {}

baidu {}

xiaomi {}

tencent {}

taobao {}

...

}

productFlavors.all { flavor ->

flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]

}

}

dependencies {

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

compile 'com.android.support:support-v4:21.0.3'

compile 'com.jakewharton:butterknife:6.0.0'

...

}

## 美团快速脚本打包方案: ##

美团前期打包方案 :

https://tech.meituan.com/mt-apk-packaging.html

原理:是在

MET-INF文件夹中添加个空文件 不需要重新编译  命名上得以支持  应用启动的时候来读取名字 区分渠道

后期由于sdk会就行签名校验 APK Signature Scheme v2

https://tech.meituan.com/android-apk-v2-signature-scheme.html

原理:是找个不受保护的 apksingblock这个区域 添加 id_value操作   写入渠道信息  然后进行读取

项目地址:https://github.com/Meituan-Dianping/walle

## 两种打包的使用场景 : ##

对于第一种:友盟打包 主要用于小公司 由于友盟有统计平台 可以直观的看到各个渠道的情况 缺点是:每次打包的时候 对于每个渠道都得重新编译 时间消耗长

对于第二种 :打包时间短  只需要编译一个包 通过复制修改内部信息 来做到各个渠道的区别 应用每次启动 来读取文件信息 请求接口 的时候带来区分多渠道  缺点是: 需要后台自己去做统计 成本较高

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • build.gradle配置参数详解 //声明是Android程序 apply plugin: 'com.andr...
    风筝李阅读 232评论 0 2
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,446评论 25 708
  • # 一度蜜v3.0协议 --- # 交互协议 [TOC] ## 协议说明 ### 请求参数 下表列出了v3.0版协...
    c5e350bc5b40阅读 672评论 0 0
  • 小陈刚过完三周岁生日,给小儿唱完“生日快乐……”小陈心里幸福的感觉都溢出来了,高兴得手舞足蹈,嘴巴捂着小手窃笑,看...
    心花怒放的日子啊阅读 482评论 0 0
  • “当时的他是最好的他,后来的我是最好的我。可是最好的我们之间,隔了一整个青春。怎么奔跑也跨不过的青春,只好伸出手道...
    十点三十八阅读 271评论 0 0