You are using a custom ProGuard settings file for obfuscation / minimization called proguard_legacy.cfg
It is very likely that this file contains some rules that are no longer compatible with DEX processing. It is recommended that you use the default ProGuard configuration file from the SDK, which is provided by Google, and is guaranteed to work with DEX processing.
Either you can disable minimization all together, as you already know ( minifyEnabled false ), or you can try and use the default ProGuard configuration. For the latter, change this line in the gradle file:
proguardFiles 'proguard_legacy.cfg'
to
proguardFiles getDefaultProguardFile('proguard-android.txt')
There is another configuration file in the SDK called "proguard-android-optimize.txt", but it is a bit more aggressive in modifying your binary, so it may not work at all.
You can add more relaxed or stricter rules in addition to the standard rules by adding them to the new ProGuard configuration and listing them next to the standard rules in the gradle file, for example:
proguardFiles getDefaultProguardFile('proguard-android.txt'),'my_proguard_rules.pro'
Any rules from the second file will be added at the top of the rules from the first. (Often, overriding the behavior of certain rules.)
Pay attention . Using the default ProGuard rules can change your code in a way that can cause problems (for example, methods or classes are completely renamed or deleted). There may be certain rules in your custom configuration file as to what should be kept unchanged. Despite the file, it is difficult to determine how to configure the ProGuard.
It is also possible that some of the security-related properties of your application change as ProGuard rules change, so if your project has security concerns, then do an intrusion / security analysis of the application after the change.