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?
“AndroidBuilder.packageApk()” creates a Packager and calls on it addResourcesFromJar() with all dependency jars. * the packager creates “JavaAndNativeResourceFilter” internally and uses it to filter the resources; * that filter throws a DuplicateFileException exception in case target entry is already found;
Unfortunately that all is (as Luke said) pure java, that means that we left only bytecode manipulation (class loaders/instrumentation).
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.