キーストアのパスワードをプレーン テキストで記述しないようにするために、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 が提供する 2 つの可能性を試しました: task.dependsOnとtask.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でキーストアのパスワードが必要なことです。
補足として、これは私が望むように機能します
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を使用するたびにパスワードを要求されます
ありがとう!
編集
@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 しか生成されません