Sharing violations while aspetctj weaving in Windows


(Nigel Heron) #1

Hi,
We have a custom android gradle plugin that does compile time weaving in order to instrument networking access.
We weave the AARs found in the app’s classpath (in build/intermediate/exploded-aar) and JARs that are found to be dependencies of the app (most are in ~/.gradle/caches).
This works great in OSX however in Windows we are unable to overwrite the original jars with our weaved jars due to FileSystemException sharing violations (“The process cannot access the file because it is being used by another process”).
Turning off Windows Defender or search indexer doesn’t help. The SysInternals Procmon tool shows that the files are already open by the same process/thread as the one trying to overwrite the orignal jars which is the gradle java.exe process.
We are doing the AAR weaving in a Javacompile.doFirst and the dependency JAR weaving in a Javacompile.doLast task.
I tried turning off daemon by setting org.gradle.daemon=false in gradle.properties with no change.

Has anyone encountered this issue under Windows? The files seem to be open by gradle, is there a way to close them before weaving?
Should we be doing it in another task that doesn’t already have the files open?

thanks,


(Lari Hotari) #2

Hi Nigel,

Thanks for reporting the issue. Would you be able to provide an example app that reproduces the problem?

One thing that you could try as a workaround is to add this line to the top of your settings.gradle or build.gradle file:

new URL("jar:file://valid_jar_url_syntax.jar!/").openConnection().setDefaultUseCaches(false)

Does this workaround help?

Regards,

Lari