Intercept gradle library calls

Hello,

I’ve encountered a dreaded error duplicate files during packaging of apk problem. I.e. gradle android plugin tries to combine files from all dependencies into a single archive and fails if there are files with the same names at the same paths at different dependency files.

Unfortunately, the android plugin is closed source (at least I was not able to find its sources at the net), that’s why it’s not possible to explicitly check the processing there. However, I have a strong assumption that it does relate to standard gradle facilities for the task of extracting dependency files and building an archive from them. That makes me think that it might be possible to intercept that calls (define own ‘interceptor closure’ for the target methods) which performs necessary cleanup (adds a property to ignore duplicate files OR apply a filter for the dependency content files with a manually provided list of files to ignore during processing).

Any ideas on what standard gradle classes/methods should be tried to be instrumented that way?

Regards, Denis

Gradle is implemented in Java, so monkey patching is not possible (or where it is it is not reliable).

See the end of http://tools.android.com/tech-docs/new-build-system for instructions on how to get the source and contribute.

That’s sad :frowning:

But thanks for the info!

Denis

For those interested in details:

Unfortunately that all is (as Luke said) pure java, that means that we left only bytecode manipulation (class loaders/instrumentation).

We’ll try that approach.

Denis

Btw, is there an easy way to setup custom classloader for a gradle plugin? May be ability to tweak jvm args for gradle process via build.gradle?

I.e. the main idea is write a self-contained code (gradle plugin?) which tweaks loading of android gradle plugin classes and modifies their byte code on the fly during loading into jvm.

Denis

Gradle doesn’t provide any suitable hooks for this that I can think of. I’m not sure where I’d start if trying to do this.

I guess I wouldn’t and I’d try to get the patch in upstream :slight_smile:

Thanks