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

I am working on integrating proguard with my gradle construct for an application written in Kotlin. I found that proguard removes the standard Kotlin library (as in my simple Hello World program), but it leaves a bunch of files in my bank that have the .kotlin_builtins file .kotlin_builtins . When I configure the gradle task to exclude these files, the program still works fine. What kind of files are these and should they be sent with my executable uberjar?

Here is my contents of the build.gradle file for reference:

 buildscript { ext.kotlin_version = '1.0.5' ext.shadow_version = '1.2.4' repositories { mavenCentral() maven { url "https://plugins.gradle.org/m2/" } flatDir dirs: "gradle/proguard" } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "com.github.jengelman.gradle.plugins:shadow:$shadow_version" classpath ":proguard:" } } apply plugin: 'kotlin' apply plugin: 'application' apply plugin: 'com.github.johnrengelman.shadow' mainClassName = 'namespace.MainKt' defaultTasks 'run' repositories { mavenCentral() } dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" testCompile "junit:junit:4.12" testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" } shadowJar { exclude 'kotlin/**/*.kotlin_builtins' exclude '.keep' } task minify(type: proguard.gradle.ProGuardTask, dependsOn: 'shadowJar') { libraryjars "${System.getProperty('java.home')}/lib/rt.jar" injars 'build/libs/artful-all.jar' outjars 'build/libs/artful-all.out.jar' printmapping 'build/libs/out.map' keepclasseswithmembers 'public class * { \ public static void main(java.lang.String[]); \ }' assumenosideeffects 'class kotlin.jvm.internal.Intrinsics { \ static void checkParameterIsNotNull(java.lang.Object, java.lang.String); \ }' } 
+8
source share
2 answers

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

When using these files, there are two main scenarios:

1) The compiler searches for them from kotlin-runtime in the classpath to determine which inline declarations are available.

2) The reflection library ( kotlin-reflect ) downloads these files as resources to provide the ability to reflect embedded ads. For example, String::class.members returns all members of the kotlin.String class in the same way that the Kotlin compiler sees these members (despite the fact that there is no kotlin/String.class , and it was deleted before java.lang.String in bytecode)).

The first paragraph is clearly not applicable in your case. And if you do not use reflection of built-in classes, I think that it is possible to completely exclude .kotlin_builtins files from the resulting banner.

+9
source

You can optimize / omit them in your JAR / APK:

 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

0
source

Source: https://habr.com/ru/post/1013018/


All Articles