安卓多渠道apk配置不同签名

一般签名都是放在buildTypes里面:

groovy 复制代码
...
android {
    ...
    defaultConfig {...}
    signingConfigs {
        release {
            storeFile file("myreleasekey.keystore")
            storePassword "password"
            keyAlias "MyReleaseKey"
            keyPassword "password"
        }
    }
    buildTypes {
        release {
            ...
            signingConfig signingConfigs.release
        }
    }
}

但是多渠道时,使用配置的优先级从高到低分别是buildTypes、productFlavor、defaultConfig,如果按上面配置的话,根本修改不了签名。所以修改成以下:

groovy 复制代码
android {
    ...
    signingConfigs {
        release {
            storeFile file("myreleasekey.keystore")
            storePassword "password"
            keyAlias "MyReleaseKey"
            keyPassword "password"
        }
        demo {
            storeFile file("myreleasekey.keystore")
            storePassword "password"
            keyAlias "MyReleaseKey"
            keyPassword "password"
        }
    }
    defaultConfig {
        signingConfig signingConfigs.release //默认签名
    }
    buildTypes {
        debug{
            signingConfig null //这里一定要置null,否则gralde会插入默认签名
        }
        release{...}
    }
    // Specifies one flavor dimension.
    flavorDimensions "version"
    productFlavors {
        demo {
            dimension "version"
            applicationIdSuffix ".demo"
            versionNameSuffix "-demo"
            signingConfig signingConfigs.demo //渠道签名
        }
        full {
            dimension "version"
            applicationIdSuffix ".full"
            versionNameSuffix "-full"
        }
    }
}

按上面配置完后,渠道可以按照自己需求替换签名了。特别注意debug类型那里要置signingConfig null,否则编译debug版本时签名会不生效,因为gradle会插入默认签名,替换掉渠道的签名。

相关推荐
一笑的小酒馆19 小时前
Android launcher3实现简单的负一屏功能
android
xuyin120419 小时前
【Android】Flow基础知识和使用
android
李新_21 小时前
基于Markwon封装Markdown组件
android·aigc·markdown
Non-existent9871 天前
Flutter + FastAPI 30天速成计划自用并实践-第10天-组件化开发实践
android·flutter·fastapi
@老蝴1 天前
MySQL数据库 - 约束和联合查询
android·数据库·mysql
ljt27249606611 天前
Compose笔记(六十一)--SelectionContainer
android·笔记·android jetpack
有位神秘人1 天前
Android中Compose系列之按钮Button
android
AI科技摆渡1 天前
GPT-5.2介绍+ 三步对接教程
android·java·gpt
csdn12259873361 天前
Android12 新启动页到底该怎么做
android·启动页
aaajj1 天前
【Android】关于MY_PACKAGE_REPLACED广播
android