Skip to content

Commit

Permalink
Fix #87 - Get release password via dialog when Gradle runs as daemon
Browse files Browse the repository at this point in the history
* If gradle is not running as a daemon, get key/keystore password via command line input
* Update README for current release process
* Bump Gradle wrapper and plugin versions, as well as buildSdkVersion
  • Loading branch information
barbeau committed Jul 22, 2017
1 parent f33d278 commit 69700af
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
40 changes: 35 additions & 5 deletions GPSTest/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import groovy.swing.SwingBuilder

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "23.0.3"
buildToolsVersion '25.0.2'

defaultConfig {
minSdkVersion 9
Expand Down Expand Up @@ -61,11 +63,39 @@ android {
}
}

/**
* Ask for keystore/key passwords on the command line or popup UI when running release builds
*/
task askForPasswords << {
// Must create String because System.readPassword() returns char[]
// (and assigning that below fails silently)
def storePw = new String(System.console().readPassword("\nKeystore password: "))
def keyPw = new String(System.console().readPassword("Key password: "))
def console = System.console()
def storePw
def keyPw

if (console) {
// Must create String because System.readPassword() returns char[]
// (and assigning that below fails silently)
storePw = new String(console.readPassword("\nKeystore password: "))
keyPw = new String(console.readPassword("Key password: "))
} else {
// Gradle is running as a daemon - prompt user to enter passwords via popup UI (#87)
new SwingBuilder().edt {
dialog(modal: true, title: 'Enter credentials', alwaysOnTop: true, resizable: true,
locationRelativeTo: null, pack: true, show: true
) {
vbox {
label(text: "Keystore passphrase:")
textField id: "storeText", input = passwordField()
label(text: "Key passphrase:")
textField id: "keyText", input = passwordField()
button(defaultButton: true, text: 'OK', actionPerformed: {
storePw = storeText.text;
keyPw = keyText.text;
dispose();
})
}
}
}
}

android.signingConfigs.release.storePassword = storePw
android.signingConfigs.release.keyPassword = keyPw
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ The below steps will help you build and run the project. For a Developer's Guid

### Release builds

To build a release build, you need to create a "gradle.properties" file that points to a "secure.properties" file, and a "secure.properties" file that points to your keystore and alias. The `gradlew assembleRelease` command will prompt for your keystore passphrase.
To build a release build, you first need to create a `gradle.properties` file that points to a `secure.properties` file, and a `secure.properties` file that points to your keystore and alias.

The "gradle.properties" file is located in the `\GPSTest` directory and has the contents:
The `gradle.properties` file is located in the `\GPSTest` directory and has the contents:

```
secure.properties=<full_path_to_secure_properties_file>
Expand All @@ -67,6 +67,14 @@ key.alias=<key_alias_name>

Note that the paths in these files always use the Unix path separator `/`, even on Windows. If you use the Windows path separator `\` you will get the error `No value has been specified for property 'signingConfig.keyAlias'.`

To build the release build, run:

`gradlew assembleRelease`

If Gradle is running as a daemon, you'll be prompted for the keystore/key password via a popup dialog box. If you're not running Gradle as a daemon, command will prompt for your passwords (See https://github.com/barbeau/gpstest/issues/87).

If you want to force Gradle to not run as a daemon, use `gradlew assembleRelease -Dorg.gradle.daemon=false`.

### Contributing

We welcome contributions to the project! Please see our [Contributing Guide](https://github.com/barbeau/gpstest/blob/master/CONTRIBUTING.md) for details, including Code Style Guidelines and Template.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:2.3.3'
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

0 comments on commit 69700af

Please sign in to comment.