Skip to content

ihrthk/android-gradle-mulchannel-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

android-gradle-mulchannel-plugin

Gradle plugin for multiple channel apks

demo

Contents

Overview

This plugin generates multiple apks from different channel. Generation has to be invoked as additions gradle task.

  • inputFile-config input file
  • tempDir-config unzip dir
  • outputDir-config output dir
  • channels-config multiple channels

Theory

If adding empty file in "META-INF" directory, do not need to sign the application.Therefore, by adding different empty file for the application of the different channels, can be the only one channel.

Testing

demo Rate = 10apk/20sec(300apk/10min)

1.Add plugin declare in build.gradle file

plugins {
  id "me.zhangls.mulchannel" version "0.2"
}

2.Config mulchannel extension(inputFile,tempDir,outputDir,channels),eg:

mulchannel {
    inputFile = file('lite-cmxj-debug.apk')
    tempDir = file('temp')
    outputDir = file('out')
    channels = ["qihu360","baidu","yingyongbao","wandoujia","taobao","xiaomi","nearme","anzhuo","anzhi","meizu"]
}

3.Use gradle mulchannel to make multiple channel apks

1.Use gradle install command,To install the plug in local maven

2.Add dependency to the top-level build.gradle file.

  buildscript {
    repositories {
      maven {
        url "https://plugins.gradle.org/m2/"
      }
    }
    dependencies {
      classpath "gradle.plugin.me.zhangls:android-gradle-mulchannel-plugin:0.2"
    }
  }

3.Apply plugin and add configuration to build.gradle of the application, eg:

apply plugin: 'me.zhangls.mulchannel'

4.Config mulchannel extension(inputFile,tempDir,outputDir,channels),eg:

mulchannel {
    inputFile = file('lite-cmxj-debug.apk')
    tempDir = file('temp')
    outputDir = file('out')
    channels = ["qihu360","baidu","yingyongbao","wandoujia","taobao","xiaomi","nearme","anzhuo","anzhi","meizu"]
}

5.Use gradle mulchannel to make multiple channel apks

  public static String getChannel(Context context) {
    ApplicationInfo appinfo = context.getApplicationInfo();
    String sourceDir = appinfo.sourceDir;
    String ret = "";
    ZipFile zipfile = null;
    try {
        zipfile = new ZipFile(sourceDir);
        Enumeration<?> entries = zipfile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = ((ZipEntry) entries.nextElement());
            String entryName = entry.getName();
            if (entryName.startsWith("META-INF/mulchannel")) {
                ret = entryName;
                break;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (zipfile != null) {
            try {
                zipfile.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
  
    String[] split = ret.split("_");
    if (split != null && split.length >= 2) {
        return ret.substring(split[0].length() + 1);
  
    } else {
        return "";
    }
  }

Will <meta-data android:value="Channel ID" android:name="UMENG_CHANNEL"/>
Channel ID replace the name of the marketing channels you apply
e.g. <meta-data android:value="Wandoujia" android:name="UMENG_CHANNEL"/>

If you don't want to in AndroidManifest.xml to config channel of umeng,you can also in Activity to config.
Please in launch activity to involved this method:AnalyticsConfig.setChannel(String channel)

keytool -list -printcert -jarfile app.apk
The output will reveal the signature owner/issuer and MD5, SHA1 and SHA256 fingerprints.

MIT License See LICENSE file.