android多版本打包,差异化

android多版本打包,差异化

// An highlighted block
 defaultConfig {
        applicationId "xxxxxx"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0.1"
        flavorDimensions "versionCode" //同一纬度
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    //“app” 名称随便
    flavorDimensions 'app'  //同一纬度
    productFlavors {
    //test1写你对应的新建的包名 .xxx写你对应的成功的包名 会在默认的application name后面加上 .xxx
        test1{
            applicationIdSuffix ".test1"
            //versionNameSuffix "-meiye" //更改versionnamer 会在 1.0.1 后面加“” -xxx“”
            dimension "app" //同一纬度
        }
        test2{
            applicationIdSuffix ".test2"
            //versionNameSuffix "-zuyu"
            dimension "app" //同一纬度
        }
    }

//打包生成对应聚到版本名称 xxxx写入自己的名字
android.applicationVariants.all { variant ->
        variant.outputs.all { output ->// each 改为 all
            def fileName = "XXXX_${variant.productFlavors[0].name}_release.apk"
            def outFile = output.outputFile
            if (outFile != null && outFile.name.endsWith('.apk')) {
                outputFileName = fileName // output.outputFile 改为 outputFileName
            }
        }
    }

对应包的创建

在src中新建如上面我们新建两个包名 test1 和 test2 目录下的结构和src/main下一致,
如需修改app_name 比如放在string.xml中app_name 字段, 我们分辨在test1 和test2中分别创建res/vlaues/strings.xml中 分辨加入app_name 放入不同的值 。其它资源同理
示例图
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值