{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-java/issues/1479","labels_url":"https://api.github.com/repos/realm/realm-java/issues/1479/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/1479/comments","events_url":"https://api.github.com/repos/realm/realm-java/issues/1479/events","html_url":"https://github.com/realm/realm-java/pull/1479","id":107306785,"number":1479,"title":"let clean task clean jni files","user":{"login":"zaki50","id":406660,"avatar_url":"https://avatars.githubusercontent.com/u/406660?v=3","gravatar_id":"","url":"https://api.github.com/users/zaki50","html_url":"https://github.com/zaki50","followers_url":"https://api.github.com/users/zaki50/followers","following_url":"https://api.github.com/users/zaki50/following{/other_user}","gists_url":"https://api.github.com/users/zaki50/gists{/gist_id}","starred_url":"https://api.github.com/users/zaki50/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zaki50/subscriptions","organizations_url":"https://api.github.com/users/zaki50/orgs","repos_url":"https://api.github.com/users/zaki50/repos","events_url":"https://api.github.com/users/zaki50/events{/privacy}","received_events_url":"https://api.github.com/users/zaki50/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/realm/realm-java/labels/Review","name":"Review","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-09-19T03:08:41Z","updated_at":"2015-09-21T19:07:06Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/realm/realm-java/pulls/1479","html_url":"https://github.com/realm/realm-java/pull/1479","diff_url":"https://github.com/realm/realm-java/pull/1479.diff","patch_url":"https://github.com/realm/realm-java/pull/1479.patch"},"body":null},"comment":{"url":"https://api.github.com/repos/realm/realm-java/issues/comments/142079998","html_url":"https://github.com/realm/realm-java/pull/1479#issuecomment-142079998","issue_url":"https://api.github.com/repos/realm/realm-java/issues/1479","id":142079998,"user":{"login":"zaki50","id":406660,"avatar_url":"https://avatars.githubusercontent.com/u/406660?v=3","gravatar_id":"","url":"https://api.github.com/users/zaki50","html_url":"https://github.com/zaki50","followers_url":"https://api.github.com/users/zaki50/followers","following_url":"https://api.github.com/users/zaki50/following{/other_user}","gists_url":"https://api.github.com/users/zaki50/gists{/gist_id}","starred_url":"https://api.github.com/users/zaki50/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zaki50/subscriptions","organizations_url":"https://api.github.com/users/zaki50/orgs","repos_url":"https://api.github.com/users/zaki50/repos","events_url":"https://api.github.com/users/zaki50/events{/privacy}","received_events_url":"https://api.github.com/users/zaki50/received_events","type":"User","site_admin":false},"created_at":"2015-09-21T19:07:06Z","updated_at":"2015-09-21T19:07:06Z","body":"@kneth I think it's too heavy to re-download 200MB realm-core after every clean.\r\nI propose to keep archive and to clean only extracted files when clean task executed.\r\nAnd to ensure downloaded archive is not corrupted, I also propose to check\r\nthe hash of archive.\r\nThat check also guarantees the integrity of download file(not altered by some attackers).\r\n\r\n```\r\ndiff --git a/realm-jni/build.gradle b/realm-jni/build.gradle\r\nindex 11204a0..d213d1b 100644\r\n--- a/realm-jni/build.gradle\r\n+++ b/realm-jni/build.gradle\r\n@@ -1,4 +1,7 @@\r\n+import java.security.MessageDigest\r\n+\r\n ext.coreVersion = '0.93.0'\r\n+ext.coreSha256Hash = '90044150ff6019a31c044306becccc513c7394f7486ffc8ba4880121c1ef46fa'\r\n ext.clang = false // gcc is default for the NDK. It also produces smaller binaries\r\n \r\n def commonCflags = [ '-std=c++11', '-ffunction-sections', '-fdata-sections', '-flto' ]\r\n@@ -59,14 +62,14 @@ def targets = [\r\n \r\n buildscript {\r\n     repositories {\r\n-        mavenCentral()\r\n+        jcenter()\r\n     }\r\n     dependencies {\r\n-        classpath 'de.undercouch:gradle-download-task:1.0'\r\n+        classpath 'de.undercouch:gradle-download-task:2.0.0'\r\n     }\r\n }\r\n \r\n-apply plugin: 'download-task'\r\n+apply plugin: 'de.undercouch.download'\r\n \r\n Properties localProperties = new Properties()\r\n localProperties.load(new FileInputStream(\"${projectDir}/../local.properties\"))\r\n@@ -89,18 +92,48 @@ task checkProperties(group: 'check', description: 'Check the user provided gradl\r\n     }\r\n }\r\n \r\n-// TODO: Split this task into smaller subtasks\r\n+ext.archiveFile = project.file(\"../core-android-${project.coreVersion}.tar.gz\")\r\n+ext.coreDir = new File(buildDir, \"core-${project.coreVersion}\")\r\n+\r\n task downloadCore(group: 'build setup', description: 'Download the latest version of realm core', dependsOn: checkProperties) {\r\n-    outputs.dir \"../core-${project.coreVersion}\"\r\n+    outputs.upToDateWhen {\r\n+        if (!project.archiveFile.exists()) {\r\n+            return false\r\n+        }\r\n+\r\n+        MessageDigest sha = MessageDigest.getInstance(\"SHA-256\");\r\n+        Formatter hexHash = new Formatter()\r\n+        sha.digest(project.archiveFile.bytes).each { b -> hexHash.format('%02x', b) }\r\n+        return project.coreSha256Hash.equals(hexHash.toString())\r\n+    }\r\n+\r\n     doLast {\r\n         download {\r\n             src \"http://static.realm.io/downloads/core/realm-core-android-${project.coreVersion}.tar.gz\"\r\n-            dest new File(buildDir, \"core-android-${project.coreVersion}.tar.gz\")\r\n+            dest project.archiveFile\r\n             onlyIfNewer true\r\n         }\r\n+    }\r\n+}\r\n+\r\n+task verifyCore(type: de.undercouch.gradle.tasks.download.Verify, dependsOn: downloadCore) {\r\n+    src       project.archiveFile\r\n+    algorithm 'SHA-256'\r\n+    checksum  project.coreSha256Hash\r\n+}\r\n+\r\n+task deployCore(group: 'build setup', description: 'Deploy the latest version of realm core', dependsOn: verifyCore) {\r\n+    doLast {\r\n+        exec {\r\n+            commandLine = [\r\n+                    'rm',\r\n+                    '-rf',\r\n+                    project.coreDir.getAbsolutePath()\r\n+            ]\r\n+        }\r\n         copy {\r\n-            from tarTree(new File(buildDir, \"core-android-${project.coreVersion}.tar.gz\"))\r\n-            into \"../core-${project.coreVersion}\"\r\n+            from tarTree(project.archiveFile)\r\n+            into project.coreDir\r\n         }\r\n         for (target in targets) {\r\n             exec {\r\n@@ -113,13 +146,6 @@ task downloadCore(group: 'build setup', description: 'Download the latest versio\r\n                 ]\r\n             }\r\n         }\r\n-        exec {\r\n-            commandLine = [\r\n-                    'rm',\r\n-                    '-rf',\r\n-                    \"${projectDir}/build/*\"\r\n-            ]\r\n-        }\r\n     }\r\n }\r\n \r\n@@ -143,7 +169,7 @@ targets.each { target ->\r\n     task \"buildAndroidJni${target.name.capitalize()}\"(type: Exec) {\r\n         group 'build'\r\n         description \"Build the Android JNI shared library for the ${target.name.capitalize()} platform\"\r\n-        dependsOn downloadCore\r\n+        dependsOn deployCore\r\n         dependsOn \"generateNdkToolchain${target.toolchain.name.capitalize()}\"\r\n         environment PATH: \"${buildDir}/standalone-toolchains/${target.toolchain.name}/bin:${System.env.PATH}\"\r\n         environment CC: \"${target.toolchain.commandPrefix}-${clang?'clang':'gcc'}\"\r\n@@ -153,10 +179,10 @@ targets.each { target ->\r\n             'make',\r\n             '-C', \"${projectDir}/src\",\r\n             \"CC_IS=${clang?'clang':'gcc'}\",\r\n-            \"REALM_CFLAGS=-Wno-variadic-macros -DREALM_HAVE_CONFIG -DPIC -I${projectDir}/../core-${project.coreVersion}/include\",\r\n+            \"REALM_CFLAGS=-Wno-variadic-macros -DREALM_HAVE_CONFIG -DPIC -I${project.coreDir}/include\",\r\n             \"CFLAGS_ARCH=${(commonCflags + target.cflags).join(' ')}\",\r\n             \"BASE_DENOM=${target.name}\",\r\n-            \"REALM_LDFLAGS=-lrealm-android-${target.name} -lstdc++ -lsupc++ -llog -L${projectDir}/../core-${project.coreVersion} -Wl,--gc-sections -flto\",\r\n+            \"REALM_LDFLAGS=-lrealm-android-${target.name} -lstdc++ -lsupc++ -llog -L${project.coreDir} -Wl,--gc-sections -flto\",\r\n             'LIB_SUFFIX_SHARED=.so',\r\n             \"librealm-jni-${target.name}.so\"\r\n         ]\r\n```\r\n\r\nIf this change is acceptable, I will make separate PR.\r\n"}}