'Overridden library java class fails during release build with r8

Currently I'm using library. Assume it's called com.example. And it has a file com.example.File.java which I have overridden by creating my own File.java under same path of com.example in my app project. It works as expected with debug builds, where I successfully inject my own version of File.java. But when I try to build release using r8 I get error:

Type com.example.File$1 is defined multiple times: <...>

So I tried using android packaging options:

packagingOptions {
    exclude 'com/example/**'
}

In hopes of at least completely removing mentioned file (and all others in that path), but I still get same error. How to properly exclude file from packagingOptions or is this not the right place for that?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source