You have to build twice. classes.dex contains R.class which is generate from the res compilation. So by the time you're computing the CRC32 it's too late to put it in.
In general you really shouldn't be modifying the model during task execution. In fact, Gradle will introduce task parallelization that really will require to not touch the model when the task are running. So we're going to (try to) fix this by making it impossible to do this. I just filed https://code.google.com/p/android/issues/detail?id=82574 So I would do the following: - in the evaluation phase of your project, read a file that contains the CRC and set it as a resources. Something like this (using Guava): android.applicationVariants.all { variant -> variant.resValue "string", "CRC", com.google.common.io.Files.toString(file("$buildDir/intermediates/checksum/$variant.dirName/classes.crc32"), Charsets.UTF_8) } - setup a task that creates the file that contains the CRC32. android.applicationVariants.all { variant -> variant,outputs.each { // create the task here. it depends on the dex task, and make the outputs.packageApplication task depend on it. } } Note: this is not enough. What you know need to do is ensure that if the newly computed CRC32 is different than the current file, the build breaks, forcing you to build a 2nd time. This way you have the two cases: - CRC32 file is missing or the content is incorrect. You compute the new CRC32, put it in the file and fail the build forcing to build again with this new value. - CRC32 is already valid, which mean the resource contains the right value, the task does nothing more and the build continues. On Sat, Dec 13, 2014 at 9:22 AM, <develo...@goseet.com> wrote: > I'm trying to calculate CRC32 of classes.dex and save as a resource value. > > Currently I have something like the following but it doesn't work. > > tasks.whenTaskAdded { theTask -> > if (theTask.name.startsWith("dex")) { > theTask.doLast { task -> > > def classes = new File(task.outputFolder, "classes.dex") > > // Calculate crc32 of classes.dex file here > > android.applicationVariants.each { variant -> > variant.resValue "string", "CRC", "" + crc > } > } > } > } > > What's the correct way to do this? > > > -- > You received this message because you are subscribed to the Google Groups > "adt-dev" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to adt-dev+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Xavier Ducrohet Android SDK Tech Lead Google Inc. http://developer.android.com | http://tools.android.com Please do not send me questions directly. Thanks! -- You received this message because you are subscribed to the Google Groups "adt-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.