I just updated my app from kotlin-gradle-plugin:1....
# android
d
I just updated my app from kotlin-gradle-plugin:1.4.32 to 1.5.10. When I compiled, the following extension method no longer compiles. If I roll back to 1.4.32, it compiles again. (I've inlined some stuff to make it clearer so no need to point out the redundant lambdas. I just want to understand why it worked before, but doesn't now.) If I convert the property to a function, it also works (but i'd prefer to keep it a property). Code:
Copy code
val UByteArray.utf8:String
	get() {
		val index = this.indexOf(0u)
		val cleaned = if (index == -1) {
			{ this }()
		}
		else {
			{ this.sliceArray(0 until index) }()
		}
		return cleaned.toByteArray().toString(Charsets.UTF_8)
	}
Error Message:
Copy code
com.android.tools.r8.errors.b: Field name '$this_<get-utf8>' cannot be represented in dex format.
seems Kotlin changed how it mangles names for inline classes. Android doesn't follow JVM spec, and it breaks
d
I'll take a look. Thanks.
e
if it were just the getter name, then probably
@JvmName("getUtf8")
would work around it
not sure if it helps with the inner class outer reference name, which is what looks like you're running into, but worth a shot
d
I tried changing the utf8 name, but that didn't appear to affect it.
e
change the getter name
e.g.
@get:JvmName("getUtf8") val UByteArray.utf8: String get() = ...
or
val UByteArray.utf8: String @JvmName("getUtf8") get() = ...
d
I see. Let me give that a whirl.
Neither of those fix it.
e
yeah, it seems the JvmName doesn't have any impact on the outer reference field name. your only workaround is probably to make the lambdas not close over
this
(or extract them to a non-extension function, same thing)
should probably file a YouTrack with mcve, I don't see any existing
workaround:
Copy code
val self = this
{ self }()
etc.
d
Maybe a dumb question, but why does closing lambdas over "this" fall afoul of a field name filter?
Anyway, thanks for your help.
e
the class synthesized for the lambda needs to store a reference to the outer
this
in a field. apparently that field is getting a name mangled in a way that isn't compatible with Android.