Skip to content

HirayClay/AndroidPackPlugin

Repository files navigation

AndroidPackPlugin

gradle plugin help packing various channel apk

Why

inspired by meituan's blog 美团Android自动化之旅—生成渠道包,solution three is quite easy and perfect,but the case is written in python lang ,so i write some code with zip4j. finally i realise it is a good chance to write my own gradle plugin

Usage

add the classpath in your project build.gradle file like below(i am sorry, attributing to the bad network,the link is bad,i will claim it sooner)

    buildscript {
        repositories {
           jcenter()
        }
        dependencies {
            classpath 'pack.io.hiray.packer:core:1.0.0'
        }
    }

config the plugin in your main module buid.gradle file

apply plugin:'android.packer'

pack {
    channels = ["ele", "meizu", "huawei","xiaomi","oneplus"]
    logEnable true
    clearChannelFile true
    taskName "packTask"//default "apkPack"
}

read out the channel like this:

    public String readChannel(Context context) {
            ApplicationInfo appinfo = context.getApplicationInfo();
            String sourceDir = appinfo.sourceDir;
            String ret = "";
            String channel = "no channel";
            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.contains("channel")) {
                        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) {
                channel = ret.substring(split[0].length() + 1);
    
            }
    
            return channel;
        }

and rebuild,in the gradle task list ,will add a task named "packTask",if you omit it ,the defautl taskName is "apkPack"

just click the task and seconds later,all the apks are generated

About

🐹 gradle plugin help packing various channel apk

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages