如何用gradle执行ionic build android
2016-11-20 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
如何用gradle执行ionic build android –release的时候自动签名
假设android的platform和keystore已经有了,我们可以看到如下目录结构
其中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
假设android的platform和keystore已经有了,我们可以看到如下目录结构
其中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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询