Android马甲包开发

什么是马甲包?

马甲包是指与原APP包除了包名,签名、包名称图标等给用户加以区分的东西不一样之外,其他功能基本不变的APP包。也就是一套代码多个APP。

相关文件

1.主module的build.gradle中一些相关配置
2.AndroidManifest.xml中的一些相关配置(${}的使用)
3.不同马甲包存放路径
4.签名文件路径配置

1.build.gradle中一些相关配置


productFlavors{
    //第一个马甲包(这个名字不能带数字)
    majiaOne{}
    //第二个马甲包
    majiaTwo{}
    //第三个马甲包
    majiaThree{}
}

productFlavors.each{ flavor->
    def props =new Properties()
    //读取每个马甲包的配置信息 在/variants/${flavor.name}/config.properties"
    file("../variants/${flavor.name}/config.properties").withInputStream{ props.load(newInputStreamReader(it,"utf-8"))}
    flavor.dimension"default"
    def application_id = props.getProperty("application_id")
    def version_name = props.getProperty("version_name")
    def version_code = props.getProperty("version_code")
    def qq_app_id = props.getProperty("qq_app_id")//qq的app_id
    def wx_app_id = props.getProperty("wx_app_id")//wx的app_id
    def file_path = props.getProperty("file_path")//文件路径
    flavor.versionName version_name
    flavor.versionCode version_code.toInteger()
    flavor.applicationId application_id
    flavor.buildConfigField'String','APP_PAGE_NAME',"\"${application_id}\""
    flavor.buildConfigField'String','QQ_APP_D',"\"${qq_app_id}\""
    flavor.buildConfigField'String','WX_APP_ID',"\"${wx_app_id}\""
    flavor.buildConfigField'String','APP_FILE_PATH',"\"${file_path}\""
}

sourceSets{
    majiaOne{
        manifest.srcFile"../variants/majiaOne/AndroidManifest.xml"
        jniLibs.srcDirs = ["../variants/majiaOne/jniLibs"]
        java.srcDirs = ["../variants/majiaOne/src"]
        resources.srcDirs = ["../variants/majiaOne/src"]
        aidl.srcDirs = ["../variants/majiaOne/src"]
        renderscript.srcDirs = ["../variants/majiaOne/src"]
        res.srcDirs = ["../variants/majiaOne/res"]
        assets.srcDirs = ["../variants/majiaOne/assets"]
}

    majiaTwo{
        manifest.srcFile"../variants/majiaTwo/AndroidManifest.xml"
        jniLibs.srcDirs = ["../variants/majiaTwo/jniLibs"]
        java.srcDirs = ["../variants/majiaTwo/src"]
        resources.srcDirs = ["../variants/majiaTwo/src"]
        aidl.srcDirs = ["../variants/majiaTwo/src"]
        renderscript.srcDirs = ["../variants/majiaTwo/src"]
        res.srcDirs = ["../variants/majiaTwo/res"]
        assets.srcDirs = ["../variants/majiaTwo/assets"]
}

    majiaThree{
        manifest.srcFile"../variants/majiaThree/AndroidManifest.xml"
        jniLibs.srcDirs = ["../variants/majiaThree/jniLibs"]
        java.srcDirs = ["../variants/majiaThree/src"]
        resources.srcDirs = ["../variants/majiaThree/src"]
        aidl.srcDirs = ["../variants/majiaThree/src"]
        renderscript.srcDirs = ["../variants/majiaThree/src"]
        res.srcDirs = ["../variants/majiaThree/res"]
        assets.srcDirs = ["../variants/majiaThree/assets"]
}


2.AndroidManifest.xml中的一些相关配置(${}的使用)

  

3.不同马甲包存放路径

config.properties每个马甲包的配置信息

application_id = com.majia.majia1
version_name = 1.0.1
version_code = 100
file_path = Majia1

image

4.签名文件路径配置

在productFlavors.each中配置签名即可

def sign = props.getProperty("sign")//签名
flavor.signingConfig.storeFile file(sign)


image

如何打包

(1)Terminal命令方式

gradlew assembleRelease
gradlew assembleDebug
gradlew assembleMajiaOneRelase
gradlew assembleMajiaOneDebug
gradlew assembleMajiaTwoRelase
gradlew assembleMajiaTwoDebug
gradlew assembleMajiaThreeRelase
gradlew assembleMajiaThreeDebug

(2)Task方式

image

到此马甲包配置完毕,代码查看demo地址

你可能感兴趣的:(Android马甲包开发)