From 6f935f137d93f7ddbaa62e6b2e236687489e04b3 Mon Sep 17 00:00:00 2001 From: John Langewisch Date: Sun, 19 Nov 2017 22:57:08 -0700 Subject: [PATCH] Add prompt for keystore password on android --- templates/android/template/app/build.gradle | 73 ++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/templates/android/template/app/build.gradle b/templates/android/template/app/build.gradle index a1e725d9c..8ed932007 100644 --- a/templates/android/template/app/build.gradle +++ b/templates/android/template/app/build.gradle @@ -1,3 +1,8 @@ +import groovy.swing.SwingBuilder +import java.awt.GridBagLayout; +import java.awt.GridBagConstraints; +import javax.swing.border.EmptyBorder; + apply plugin: 'com.android.application' android { @@ -14,6 +19,16 @@ android { ::if KEY_STORE:: signingConfigs { + if (project.KEY_STORE_PASSWORD == 'null') { + def keyStoreFile = project.KEY_STORE.split('/') + keyStoreFile = keyStoreFile[keyStoreFile.length - 1] + project.KEY_STORE_PASSWORD = getPassword('\nPlease enter key password for ' + keyStoreFile + ':'); + } + + if (project.KEY_STORE_ALIAS_PASSWORD == 'null') { + project.KEY_STORE_ALIAS_PASSWORD = getPassword("\nPlease enter key alias password for alias " + project.KEY_STORE_ALIAS + ":") + } + release { storeFile file(project.KEY_STORE) storePassword project.KEY_STORE_PASSWORD @@ -64,4 +79,60 @@ dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) ::if (ANDROID_LIBRARY_PROJECTS)::::foreach (ANDROID_LIBRARY_PROJECTS)::compile project(':deps:::name::') ::end::::end:: -} \ No newline at end of file +} + +def getPassword(message) { + def password = ''; + if (System.console() == null) { + new SwingBuilder().edt { + dialog( + title: 'Enter password', + alwaysOnTop: true, + size: [350, 150], + resizable: false, + locationRelativeTo: null, + pack: true, + modal: true, + show: true + ) { + lookAndFeel('system') + + panel(border: new EmptyBorder(10, 10, 10, 10)) { + gridBagLayout() + def gbc = new GridBagConstraints(); + + gbc.gridx = 0 + gbc.gridy = 0 + gbc.fill = GridBagConstraints.HORIZONTAL + gbc.insets = [0, 0, 10, 0] + label( + text: '' + + '' + + message + + '' + + '', + constraints: gbc) + + gbc.gridy = 1 + input = passwordField(constraints: gbc) + + gbc.gridy = 2 + gbc.fill = GridBagConstraints.NONE + gbc.insets = [0, 0, 0, 0] + gbc.ipadx = 50 + button = button( + defaultButton: true, + text: 'OK', + actionPerformed: { + password = input.password + dispose() + }, + constraints: gbc) + } + } + } + } else { + password = System.console().readPassword(message) + } + return new String(password) +}