gpt4 book ai didi

android - assembleRelease 任务依赖 - 询问 keystore 密码

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:37:54 25 4
gpt4 key购买 nike

为了避免以纯文本形式写入 keystore 密码,我尝试向由 android Gradle 插件创建的 assembleRelease 任务添加依赖项。

我查看了 Gradle 文档 Manipulating existing tasks但我无法将依赖项放在它应该放置的位置

这是我的任务,在 android 插件上方的 $root$/myApp/build.gradle 中定义。

task readPasswordFromInput << {
def console = System.console()

ext.keystorePassword = console.readLine('\n\n\n> Enter keystore password: ')
}

apply plugin: 'android'

然后,我尝试了 Gradle 提供的两种可能性:task.dependsOntask.doFirst,但均无效。后者似乎被忽略了,而 dependsOn 确实添加了依赖项,但在依赖链中为时已晚。运行 ./gradlew tasks --all 打印这个

:assembleRelease - Assembles all Release builds [libs:ActionBarSherlock:bundleRelease, libs:DataDroid:bundleRelease, libs:SlidingMenu:bundleRelease]
:compileRelease
...
[SEVERAL TASKS]
...
:packageRelease
...
[SEVERAL TASKS]
...
:readPasswordFromInput

问题是,任务packageRelease中需要 keystore 密码

作为旁注,这按我想要的方式工作

buildTypes {
release {
def console = System.console()

ext.keystorePassword = console.readLine('\n\n\n> IF building release apk, enter keystore password: ')

debuggable false

signingConfigs.release.storePassword = ext.keystorePassword
signingConfigs.release.keyPassword = ext.keystorePassword

signingConfig signingConfigs.release
}
}

但每次您使用 gradlew 时它都会询问密码,无论是clean 还是 assemble

谢谢!

编辑

感谢@Intae Kim,这是我的 build.gradle 2.0 版

task readPasswordFromInput << {
def console = System.console()

ext.keystorePassword = console.readLine('\n\n\n> Enter keystore password: ')

android.signingConfigs.release.storePassword = ext.keystorePassword
android.signingConfigs.release.keyPassword = ext.keystorePassword
}

tasks.whenTaskAdded { task ->
if (task.name == 'validateReleaseSigning') {
task.dependsOn readPasswordFromInput
}
}

apply plugin: 'android'

然后,buildTypes

release {
debuggable false

signingConfig signingConfigs.release

runProguard true
proguardFile 'my-file.txt'
}

Gradle 正确执行,但它只生成一个 release-unsigned.apk

最佳答案

尝试:

tasks.whenTaskAdded { task ->
if (task.name == 'packageRelease') {
task.dependsOn readPasswordFromInput
}
}

使用您的 readPasswordFromInput 任务。

更新:

通过这种方式,您可以看到以下代码有效。

def runTasks = gradle.startParameter.taskNames
if ('assemble' in runTasks || 'assembleRelease' in runTasks || 'a' in runTasks || 'aR' in runTasks) {
android.signingConfigs.releaseSign.storeFile = file('/path/to/keystore')
android.signingConfigs.releaseSign.storePassword = System.console().readLine('KeyStore Password: ')
android.signingConfigs.releaseSign.keyAlias = ...
android.signingConfigs.releaseSign.keyPassword = System.console().readLine('Alias Password: ')
android.buildTypes.release.signingConfig = android.signingConfigs.releaseSign
}

如果遇到构建失败,可能需要在 android.signingConfig 上分配一个空的 keysign 配置:

android {
...
signingConfigs {
releaseSign
}
...

关于android - assembleRelease 任务依赖 - 询问 keystore 密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17144878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com