Q:

How to exclude package-info.java files from dex?

I have a multi-module Android application and when I build the release APK, I get this dex error:
java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/XX/package-info;

I do of course have a package-info file in all my modules and they all have the same name.
Why does dex even care about package-info files, and how can I configure it to ignore them?
Note: I do NOT want to enable multi-dex

A:

The solution is to exclude the package-info files from the jar files.  
Example code to use in build.gradle files
for java-modules:
jar {
    exclude('com/**/package-info.*')
}

for android-modules:
android {
    sourceSets.main.java.filter.exclude 'com/**/package-info.*'
}

Works with:

Android Studio 3.0 Canary 5
Gradle 4.1-milestone-1
Android gradle plugin: 3.0.0-alpha5

Note: you can of course only then exclude the package-info files if they don't contribute to your build!
e.g. when you use immutables style-configuration in your package-info file then you cannot exclude the files from the build, because then the names of the generated files may change!

