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

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

NewImage

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

storeFile=YiShangpu.keystore
key.store.password=your password
key.alias=YiShangpu
key.alias.password=your password

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

可以参考官方的文档https://cordova.apache.org/docs/en/edge/guide_platforms_android_tools.md.html

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
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇