安卓多渠道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会插入默认签名,替换掉渠道的签名。

相关推荐
还是奇怪2 小时前
Linux - 安全排查 3
android·linux·安全
Android采码蜂3 小时前
BLASTBufferQueue03-BufferQueueConsumer核心操作
android
Android采码蜂3 小时前
BLASTBufferQueue02-BufferQueueProducer核心操作
android
2501_915921433 小时前
没有Mac如何完成iOS 上架:iOS App 上架App Store流程
android·ios·小程序·https·uni-app·iphone·webview
码农明明4 小时前
Google Play 应用上架二三事
android·google
红橙Darren7 小时前
手写操作系统 - 环境搭建
android·微信·操作系统
_一条咸鱼_7 小时前
Android Runtime直接内存管理原理深度剖析(73)
android·面试·android jetpack
你听得到117 小时前
揭秘Flutter图片编辑器核心技术:从状态驱动架构到高保真图像处理
android·前端·flutter
wilinz7 小时前
Flutter Android 端接入百度地图踩坑记录
android·flutter
小袁拒绝摆烂10 小时前
SQL开窗函数
android·sql·性能优化