Created
April 26, 2017 15:27
-
-
Save timkrins/366d42fcf39a4341678438dedb33896f to your computer and use it in GitHub Desktop.
Generate Google Maps hash at end of Gradle build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.regex.Pattern | |
def getGoogleMapsHash = { -> | |
def pattern = Pattern.compile("SHA1: ([0-9a-fA-F:]+)") | |
try { | |
def stdOut = new ByteArrayOutputStream() | |
exec { | |
commandLine "keytool", "-list", "-v", "-keystore", file(STORE_FILE), "-storepass", STORE_PASSWORD | |
standardOutput = stdOut | |
} | |
def hashString = stdOut.toString().trim() | |
def matcher = pattern.matcher(hashString) | |
matcher.find() | |
return matcher.group(1) | |
} | |
catch (error) { | |
return error.toString(); | |
} | |
} | |
gradle.buildFinished { | |
println "Google Maps Hash:\n " + getGoogleMapsHash() + "\n" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
STORE_FILE=C:/Keystore.jks | |
STORE_PASSWORD=password | |
KEY_ALIAS=keystoreAlias | |
KEY_PASSWORD=password |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment