需要获取设备的系统权限,由于厂商较多,不同的app需要的系统签名文件不一致,每次打包都得对应不同的文件,为了方便管理维护和app能够获取到自身的打包渠道以实现相应的功能,笔者基于Gradle实现分渠道打包,并记录整理如下。文中如有不到之处,欢迎指导交流。
QQ 2903368986
productFlavors
中文翻译产品风味
,也就是用于定义产品的特性或者说不同的地方,通过配置里面的参数我们就可以用一套代码编译出多个渠道的产品。
flavorDimensions "channel"
productFlavors {
/***
* 渠道1
*/
flavor1 {
//自定义属性
buildConfigField "String", "key", '"value1"'
//重定义appid
applicationId "xxx.xxx.xxx"
//重定义versionName
versionName "1.0.0"
//重定义版本
versionCode 1
//重定义value资源
resValue "string", "app_name", "***"
...
}
/**
* 渠道2
*/
flavor2 {
buildConfigField "String", "key", '"value2"'
...
}
}
ExtraPropertiesExtension
是Gradle领域对象的一个属性,我们可以将自定义的属性添加到它的ext
扩展名上
关于ExtraPropertiesExtension的详细文档
ext {
path1 = '你的文件路径/***1.jks'
path2 = '你的文件路径/***2.jks'
}
从源码中可以看到sinningConfigs
的配置被保存在用于配置签名配置的DSL对象sinningConfigs中。
/**
* Encapsulates signing configurations that you can apply to {@link
* com.android.build.gradle.internal.dsl.BuildType} and {@link ProductFlavor} configurations.
*
* <p>For more information about the properties you can configure in this block, see {@link
* SigningConfig}
*/
public void signingConfigs(Action<? super NamedDomainObjectContainer<SigningConfig>> action) {
checkWritability();
action.execute(signingConfigs);
}
继续往下看我们可以配置哪些参数
/**
* Creates a SigningConfig with a given name.
*
* @param name the name of the signingConfig.
*/
@Inject
public SigningConfig(@NonNull String name) {
super(name);
}
public SigningConfig initWith(com.android.builder.model.SigningConfig that) {
//签名文件
setStoreFile(that.getStoreFile());
//密码
setStorePassword(that.getStorePassword());
//用户名
setKeyAlias(that.getKeyAlias());
//密码
setKeyPassword(that.getKeyPassword());
//是否打包v1
setV1SigningEnabled(that.isV1SigningEnabled());
//是否打包v2
setV2SigningEnabled(that.isV2SigningEnabled());
//打包类型
setStoreType(that.getStoreType());
return this;
}
很明显storefile就是我们想要的,具体配置如下
signingConfigs {
flavor1 {
storeFile file(path1)
storePassword 'xxx'
keyAlias 'xxx'
keyPassword 'xxx'
storeType 'release'
...
}
flavor2 {
storeFile file(path2)
...
}
}
到此整个配置就结束了,可以愉快的code了,如果对你有帮助的话,给我点个👍吧!
微信小程序时下大热,抱着学习的心态了解了一下,目前没有搜到完整的.NET用户数...
如果你依然使用 Windows 10 Version 1909/1903 甚至更老的系统,那么你可能已经...
在我30多年的程序员生涯里,我学到了不少有用的东西。下面是我这些年积累的经验...
XML的嵌套处理 一般情况下,我们从数据库中查询得到的结果集可能很大,所以从服...
据华尔街日报中文网26日消息,谷歌正在推进从其Chrome网络浏览器中移除一项广泛...
从业以来主要在做客户端,用到的数据库都是表结构比较简单的 SQLite,以我那还给...
从上篇内容不如题的文章《 .net core 并发下的线程安全问题 》扩展认识.net core...
springMVC解决ajax请求乱码的问题 前言: 最近在项目的使用过程中发现在springmv...
Windows10又爆出蓝屏死机Bug啦!每次Windows10更新,似乎总会带来一些莫名其妙的...
在这种配置下我们要实现关键词不区分大小写搜索并高亮显示要借助ASP的正则处理了...