Gradle插件--多渠道打包

DEMO地址:https://github.com/zhaopingfu/listener25_channel

多渠道打包

这里只是在本地写了两个插件,没有上传到jcenter上面

原理

Android7.0之后心出来了一个V2签名,通过分析是v1签名还是v2,在里面合适的位置插入渠道信息
参考链接:
    https://source.android.com/security/apksigning/
    https://source.android.com/security/apksigning/v2
    https://android.googlesource.com/platform/build/+/android-cts-7.0_r15/tools/signapk/src/com/android/signapk
在plugin模块/src/main/resources下有三张图片,是写了apk中如何存储的    

使用

  • 第一步

    将plugin模块和channel模块拷贝到项目中,并在settings.gradle中进行配置
    
    plgin模块的任务是将渠道信息写入安装包
    
    channel模块是将渠道信息读取出来
    
  • 第二步

    在命令行(Terminal)中生成插件
    
    gradlew :plugin:pCPPTML
    gradlew :channel:PCPPTML
    
  • 第三步

    修改工程的build.gradle,添加插件

示例

   buildscript {
       repositories {
           jcenter()
           mavenLocal()
       }
       dependencies {
           classpath 'com.android.tools.build:gradle:2.3.3'
           classpath 'com.pf.channel:channel-plugin:1.0.0'
       }
   }

   allprojects {
       repositories {
           jcenter()
           mavenLocal()
       }
   }
  • 第四步

    在app下创建channel.txt文件,里面存放渠道信息,一行一个渠道信息

    修改app模块下的build.gradle

示例

 apply plugin: 'com.pf.channel'
 channel {
 //    baseApk "${buildDir}/outputs/apk/app-debug.apk"
 //    outDir "${buildDir}/outputs/channel"
     baseApk "${projectDir}/app-release.apk"
     outDir "${projectDir}/channel"
     channelFile "${projectDir}/channel.txt"
 }
 dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
         exclude group: 'com.android.support', module: 'support-annotations'
     })
     compile 'com.android.support:appcompat-v7:25.3.1'
     compile 'com.android.support.constraint:constraint-layout:1.0.2'
     testCompile 'junit:junit:4.12'

     compile 'com.pf.channel:channel:1.0.0'
 }
  • 第五步

    打一个Release版本的包,将路径放在app下,名字为app-release,如果不在要在build.gradle中修改

    在命令行中打包 gradlew :app:assembleChannel

    打出来的包在/app/channel下,这些包都可以安装

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值