Code Monkey home page Code Monkey logo

apk-channelization's Introduction

Android多渠道输出脚本

这是博文另辟蹊径实现Android多渠道打包的一个简单实现,通过直接修改二进制AndroidManifest.xml实现渠道替换。

注意,只能修改编码为UTF-16的二进制AndroidManifest.xml。

替换二进制字符串核心代码来自:https://github.com/wanchouchou/playWithAXML

文件说明:

  1. signingapks.py: 签名多个apk
    ./signingapks.py <signingConfig> [--zipalignexe=path/to/zipalign] <apkfile>...
  2. repackage.py:输出渠道包
    ./repackage.py [options] <path/to/apk>
  3. 多渠道文件的格式:'#'开头为注释,不为空的字符串即为渠道名,如有文件channels
##############
#channel list#
##############
aaaa
bbb

ccc

使用方法:

  • 请先将AndroidManifest.xml渠道名改为占位符 "xxxxxxxxxxxxxxxx",如umeng渠道:
<meta-data android:name="UMENG_CHANNEL"  android:value="xxxxxxxxxxxxxxxx" />

示例:

  1. 输出当前目录source.apk的渠道包"aaa","bbb","ccc"到out目录并签名:
    ./repackage.py -c aaa,bbb,ccc -o out --keystore=android.key --keypass=android --storepass=android --keyalias=debug source.apk

  2. 输出当前目录source.apk的所有定义在文件channels中的渠道包,输出到out目录并签名
    ./repackage.py -f channels -o out --keystore=android.key --keypass=android --storepass=android --keyalias=debug source.apk

  3. 签名之前进行zipalign
    ./repackage.py -f channels -o out --zipalignexe=$ANDROID_SDK/build-tools/23.0.1/zipalign --keystore=android.key --keypass=android --storepass=android --keyalias=debug source.apk

  4. 与android gradle构建工具(1.3.0)一起使用: 在app的build.gradle中添加task如releaseAllChannels

afterEvaluate {
    android.applicationVariants.all { variant ->
        def output = variant.outputs.get(0).outputFile as File
        if ("release".equals(variant.name) && variant.signingConfig != null) {
            def task = tasks.findByName("zipalign${variant.name.capitalize()}")
            def zipalignExe = task?.zipAlignExe
            def repackageTask = tasks.create(name: "releaseAllChannels",
                    description: "Build all channel apks",
                    group: "build", type: Exec) {
                commandLine 'python', rootProject.file("repackage.py").absolutePath,
                        '-f', rootProject.file('channels').absolutePath,
                        '-o', builderOutput.absolutePath,
                        "--keystore=${variant.signingConfig.storeFile}",
                        "--keypass=${variant.signingConfig.keyPassword}",
                        "--storepass=${variant.signingConfig.storePassword}",
                        "--keyalias=${variant.signingConfig.keyAlias}",
                        "--zipalignexe=${zipalignExe}",
                        output.absolutePath
            }
            repackageTask.dependsOn variant.assemble
        }
}

执行task releaseAllChannels 即可以直接从源码编译并输出渠道包到build目录

apk-channelization's People

Contributors

nukc avatar yrom avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.