What are .kotlin_builtins files and can I omit them from my uberjars?

You can optimize/omit these from yours JARs/APKs:

packagingOptions {
  exclude "/META-INF/*.kotlin_module"
  exclude "**/kotlin/**"
}

Even better:

packagingOptions {
  exclude "/META-INF/*.kotlin_module"
  exclude "**/kotlin/**"
  exclude "**/*.txt"
  exclude "**/*.xml"
  exclude "**/*.properties"
}

Source: https://github.com/jaredsburrows/android-gif-example/blob/master/build.gradle.kts#L127


These files contain data for declarations of standard ("built-in") Kotlin classes which are not compiled to .class files, but rather are mapped to the existing types on the platform (in this case, JVM). For example, kotlin/kotlin.kotlin_builtins contains the information for non-physical classes in package kotlin: Int, String, Enum, Annotation, Collection, etc.

There are two main scenarios when these files are used:

  1. The compiler looks them up from kotlin-stdlib on the classpath to determine which built-in declarations are available.

  2. The reflection library (kotlin-reflect) loads these files as resources to provide reflection capabilities for built-in declarations. For example, String::class.members returns all members of the class kotlin.String exactly in the same way as the Kotlin compiler sees those members (despite the fact that there's no kotlin/String.class file and it's erased to java.lang.String in bytecode).

The first point is clearly not applicable in your case. And if you don't use reflection on built-in classes, I think it's safe to exclude .kotlin_builtins files completely from the resulting jar.