From 7ce6837979df3be8b5213270623c4745cec0e8ff Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Tue, 28 Jun 2022 13:42:23 -0700 Subject: [PATCH] Add -Xjvm-defaults=all to kotlin compilations This causes kotlinc to output default methods instead of DefaultsImpl inner classes. It's required for code that depends on other libraries using @JvmDefault. It will be the default in a future version of kotlin. Bug: 236431222 Test: treehugger Change-Id: I67a7cb3b816b41a441af7ec78cc64bc358c6889d --- java/base.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/java/base.go b/java/base.go index 0900daaae..b76dcc9d1 100644 --- a/java/base.go +++ b/java/base.go @@ -1072,6 +1072,13 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { kotlincFlags := j.properties.Kotlincflags CheckKotlincFlags(ctx, kotlincFlags) + // This is needed for code that depends on libraries that use @JvmDefault + // -Xjvm-default=all will be the default in a future version of kotlin + // according to https://blog.jetbrains.com/kotlin/2020/07/kotlin-1-4-m3-generating-default-methods-in-interfaces/ + if flags.javaVersion >= JAVA_VERSION_8 { + kotlincFlags = append(kotlincFlags, "-Xjvm-default=all") + } + // Workaround for KT-46512 kotlincFlags = append(kotlincFlags, "-Xsam-conversions=class")