为 debug 和 release 设置不同的包名

开发时为 debug 和 release 版本设置不同的包名,这样 debug 和 release 可以同时安装到同一个手机上。为了区分可以为 debug 和 release 设置不同的名称或设置不同的 icon。
resValue 可以操作资源,配置如下

buildTypes {
    debug {
        applicationIdSuffix '.debug'
        versionNameSuffix '-DEBUG'
        resValue 'string', 'app_name', '青青互助-debug'
    }

    release {
        resValue 'string', 'app_name', '青青互助'
    }

    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.apk')) {
                def suffix = ''
                if (variant.buildType.name.equals('release')) {
                    suffix = 'release'
                } else if (variant.buildType.name.equals('debug')) {
                    suffix = 'debug'
                }
                def fileName = "app_v${defaultConfig.versionName}_${variant.productFlavors[0].name}_${releaseTime()}_${suffix}.apk"
                output.outputFile = new File(outputFile.parent, fileName)
            }
        }
    }
}

记得删除原来 string.xml 中的 app_name,否则编译时会报资源重复

也可以为 debug 版本设置不同的 icon, 把图片扔到 app/src/debug/res 对应的目录中就行了

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,980评论 25 709
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,107评论 19 139
  • 转载注明出处:http://www.jianshu.com/p/5255b100930e 0. 前言 完全由个人翻...
    王三的猫阿德阅读 2,602评论 0 4
  • 1.介绍 如果你正在查阅build.gradle文件的所有可选项,请点击这里进行查阅:DSL参考 1.1新构建系统...
    Chuckiefan阅读 12,203评论 8 72
  • 今天看了简报术第5章图表的制作技巧34-36小节。 日常工作中难免要涉及数据分析和报告呈现,为了让观看者能一目了然...
    大棉阅读 1,037评论 0 0