ionic build android release,如何用gradle执行ionic build android –release的时候自动签名

假设android的platform和keystore已经有了,我们可以看到如下目录结构

tree.png

其中release-signing.properties这个时候应该是没有的,现在我们新建一个release-signing.properties

storeFile=YiShangpu.keystore

key.store.password=your password

key.alias=YiShangpu

key.alias.password=your password

为什么要新建这个文件呢?

cdvReleaseSigningPropertiesFile (default: release-signing.properties)

Path to a .properties file that contains signing information for release builds. The file should look like:

storeFile=relative/path/to/keystore.p12
storePassword
=SECRET1
storeType
=pkcs12
keyAlias
=DebugSigningKey
keyPassword
=SECRET2

storePassword and keyPassword are optional, and will be prompted for if omitted.

对比我们新建的内容和官方文档是有出入的,那为什么我们的需要用key.store.password这种写法呢?

我们回到项目中,打开build.gradle,找到 addSigningProps。

def addSigningProps(propsFilePath, signingConfig) {

def propsFile = file(propsFilePath)

def props = new Properties()

propsFile.withReader { reader ->

props.load(reader)

}

def storeFile = new File(props.get('key.store') ?: privateHelpers.ensureValueExists(propsFilePath, props, 'storeFile'))

if (!storeFile.isAbsolute()) {

storeFile = RelativePath.parse(true, storeFile.toString()).getFile(propsFile.getParentFile())

}

if (!storeFile.exists()) {

throw new FileNotFoundException('Keystore file does not exist: ' + storeFile.getAbsolutePath())

}signingConfig.keyAlias = props.get('key.alias') ?: privateHelpers.ensureValueExists(propsFilePath, props, 'keyAlias')

signingConfig.keyPassword = props.get('keyPassword', props.get('key.alias.password', signingConfig.keyPassword))

signingConfig.storeFile = storeFile

signingConfig.storePassword = props.get('storePassword', props.get('key.store.password', signingConfig.storePassword))

def storeType = props.get('storeType', props.get('key.store.type', ''))if (!storeType) {

def filename = storeFile.getName().toLowerCase();

if (filename.endsWith('.p12') || filename.endsWith('.pfx')) {

storeType = 'pkcs12'

} else {

storeType = signingConfig.storeType // "jks"

}

}

signingConfig.storeType = storeType

}

红色的部分便是原因了。

注意:keystore的路径需要根据实际情况设置。

最后我们执行如下命令即可获得签名后的apk文件。

$ ionic build android —release

your password

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值