Skip to content

Commit

Permalink
Fix #302 - Read key password from secure properties file for releases
Browse files Browse the repository at this point in the history
* Also bump Gradle and plugin versions, which triggered the #302 issue

# Conflicts:
#	BUILD.MD
  • Loading branch information
barbeau committed Aug 7, 2019
1 parent f048a68 commit b5b5519
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 50 deletions.
62 changes: 62 additions & 0 deletions BUILD.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
## Build Setup

The below steps will help you build and run the project.

### Prerequisites for both Android Studio and Gradle

1. Download and install the [Android SDK](http://developer.android.com/sdk/index.html). Make sure to install the Google APIs for your API level (e.g., 17), the Android SDK Build-tools version for your `buildToolsVersion` version, and the Android Support Repository and Google Repository.
2. Set the "ANDROID_HOME" environmental variable to your Android SDK location.
3. Set the "JAVA_HOME" environmental variables to point to your JDK folder (e.g., "C:\Program Files\Java\jdk1.6.0_27")

### Building in Android Studio

1. Download and install the latest version of [Android Studio](http://developer.android.com/sdk/installing/studio.html).
2. In Android Studio, choose "Import Project" at the welcome screen.
3. Browse to the location of the project, and double-click on the project directory.
4. If prompted with options, check "Use auto-import", and select "Use default gradle wrapper (recommended)". Click "Ok".
5. The default build flavor will be the `google` flavor, which is the version of GPSTest on Google Play that uses Google Play Services for maps. If you want to build the version on Fdroid that uses OSMDroid for maps, use the "Build Variants" toolbar item to select the `osmdroid` flavor.
6. Click the green play button (or 'Shift->F10') to run the project!

### Building from the command line using Gradle

1. To build and push the app to the device, run `gradlew installGoogleDebug` from the command line at the root of the project for the version of GPSTest on Google Play. If you want to build the Fdroid version with OSM Droid, then use `gradlew installOsmdroidDebug`.
3. To start the app, run `adb shell am start -n com.android.gpstest/.GpsTestActivity` for the Google Play version, or `adb shell am start -n com.android.gpstest.fdroid/.GpsTestActivity` for the Fdroid version (alternately, you can manually start the app)

### Release builds

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:

```
secure.properties=<full_path_to_secure_properties_file>
```

The "secure.properties" file (in the location specified in gradle.properties) has the contents:

```
key.store=<full_path_to_keystore_file>
key.alias=<key_alias_name>
key.storepassword=yourKeystorePassword
key.keypassword=yourKeyPassword
```

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`

## Troubleshooting

### When importing to Android Studio, I get an error "You are using an old, unsupported version of Gradle..."

If you're using Android Studio v0.4.2 or lower, when importing, please be sure to select the "settings.gradle" file in the root, **NOT** the project directory.
You will get the above error if you select the project directory / name of the project.

### I get build errors for the Android Support libraries or Google APIs

Open Android SDK Manager, and under the "Extras" category make sure you've installed both the "Android Support Repository" (in addition to the "Android Support library") as well as the
"Google Repository". Also, make sure you have the Google API installed for the API level that you're working with in the "/build.gradle" file,
including the "Android SDK Build-tools" version (at the top of the "Tools" category in the Android SDK Manager) that
matches the compileSdkVersion and buildToolsVersion numbers in /GPSTest/build.gradle.
48 changes: 2 additions & 46 deletions GPSTest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ android {
release {
storeFile file(props['key.store'])
keyAlias props['key.alias']
storePassword "askmelater"
keyPassword "askmelater"
storePassword props['key.storepassword']
keyPassword props['key.keypassword']
}
}
} else {
Expand Down Expand Up @@ -103,50 +103,6 @@ android {
}
}

/**
* Ask for keystore/key passwords on the command line or popup UI when running release builds
*/
task askForPasswords << {
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
}

tasks.whenTaskAdded { theTask ->
if (theTask.name.matches("\\bpackage\\w+Release\\b")) {
theTask.dependsOn "askForPasswords"
}
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.71'
ext.kotlin_version = '1.3.31'
repositories {
google()
jcenter()
Expand All @@ -10,7 +10,7 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Sep 24 16:04:50 EDT 2018
#Mon Jun 17 14:58:47 EDT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

0 comments on commit b5b5519

Please sign in to comment.