Skip to content

Commit

Permalink
Use gradle's project file discovery via relative path to resolve path…
Browse files Browse the repository at this point in the history
… to external dependency Math.js in res/raw
  • Loading branch information
icasdri committed Aug 10, 2016
1 parent d5ad357 commit ab7b048
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ android {
}
}

String sha256sum(String pathstr) {
java.nio.file.Path path = java.nio.file.Paths.get(pathstr);
byte[] contents = java.nio.file.Files.readAllBytes(path);
String sha256sum(File file) {
byte[] contents = java.nio.file.Files.readAllBytes(file.toPath());
java.security.MessageDigest digest = java.security.MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(contents);
return String.format("%032X", new BigInteger(1, hash));
Expand All @@ -45,9 +44,9 @@ dependencies {
compile 'com.android.support:design:23.1.1'

ant.get(src: 'http://cdnjs.cloudflare.com/ajax/libs/mathjs/3.2.1/math.min.js',
dest: 'src/main/res/raw/math.js')
dest: file('src/main/res/raw/math.js'))

assert "6CEC5DD5257A68E172E76FC5BB1EE130C420C0DAC929E3D1955ADFC859D0707F".equals(
sha256sum("app/src/main/res/raw/math.js"))
assert '6CEC5DD5257A68E172E76FC5BB1EE130C420C0DAC929E3D1955ADFC859D0707F'.equals(
sha256sum(file('src/main/res/raw/math.js')))
}

0 comments on commit ab7b048

Please sign in to comment.