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;

1.png

debug.keystore

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

http://mp.weixin.qq.com/s/YmZ8M4TEd0yfPbNag8R1bw 在美团基础上 进行封装 里面包含360加固导致的打包失败的 解决方法

两种打包的使用场景 :

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

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

更多相关文章

  1. NPM 和webpack 的基础使用
  2. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  3. 读取android手机流量信息
  4. android 使用html5作布局文件: webview跟javascript交互
  5. Android(安卓)多媒体扫描过程(Android(安卓)Media Scanner Proces
  6. android“设置”里的版本号
  7. Android开发环境搭建
  8. Android(安卓)Resource介绍和使用
  9. 2014.01.21 ——— android 关联android-support源码

随机推荐

  1. android剪切合并MP3音乐
  2. 【Android开发环境安装】
  3. 【066】Android & Java 难点解析
  4. Android Camera调用流程
  5. Android修改gen下包名
  6. Android: Android Wifi System
  7. android WebView loadData不能解析
  8. 本博博文预报
  9. 如何去写 Android(安卓)init.rc (Android
  10. 开启 Android 反射调用