Jenkins + Gradle + Android + Multi-Channel package (1), jenkinsgradle

Source: Internet
Author: User

Jenkins + Gradle + Android + Multi-Channel package (1), jenkinsgradle

The purpose is that QA can log on to Jenkins and select the version to be built. The result is notified by email (including the build information, static code analysis results, APK download link, QR code, and so on), and then archive it.

  • Build using Gralde.
  • Package and generate a QR code. archive is implemented using a Python script.
Multi-channel package

Playing multi-channel package has many methods, I use is, generate a signed APK, and then add an empty file under the APK package META-INF directory, the file name contains channel information, read this file in Android to obtain information and set it to umeng through code. This avoids repeated compilation and signature.
Modify the Python script:

def generate( channel_name ):    shutil.copy(apk_file, target_apk)    zipped = zipfile.ZipFile(target_apk, 'a', zipfile.ZIP_DEFLATED)    content_file = "META-INF/Channel_"+channel_name+".txt"    zipped.write(empty_content, content_file)    zipped.close()    return target_apk

How to retrieve channel information and modify it cyclically depends on your situation

Read from Android

private static String getContent(Context context, String channelKey){    String sourceDir = context.getApplicationInfo().sourceDir;    String key = "META-INF/" + channelKey;    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(key)) {                ret = entryName;                break;            }        }    } catch (IOException e) {        e.printStackTrace();    } finally {        if (zipfile != null) {            try {                zipfile.close();            } catch (IOException e) {                e.printStackTrace();            }        }    }    String[] split = ret.split("_");    String channel = "DEV";    if (split != null && split.length >= 2) {        channel = ret.substring(split[0].length() + 1);    }    return channel;}

Set umeng to umeng

AnalyticsConfig.setChannel(String channel)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.