Gradle插件--多渠道打包

来源:互联网 发布:核酸数据库中国 编辑:程序博客网 时间:2024/05/31 18:30

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:pCPPTMLgradlew :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下,这些包都可以安装

原创粉丝点击