In Android, since Oreo+, Member and Constructor in...
# announcements
j
In Android, since Oreo+, Member and Constructor inherit from a new Class:
java.lang.Executable
. So this small code here in Kotlin
Copy code
// val resolvedClass: Class<*>
// val resolved = mutableMapOf<MemberDec, Member>()
// MemberDec is a sealed class with MethodDec and ConstructorDec as subclasses containing name and parametertypes

resolved[member] = when (member) {
    is MethodDec -> member.findMethod(resolvedClass) // returns Method
    is ConstructorDec -> member.findConstructor(resolvedClass) // returns Constructor<*>
}
This fails because of Kotlin smart casts using a common superclass
java.lang.Executable
that does not exist on all devices.
Copy code
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/reflect/Executable;
        at com.jaqxues.akrolyb.genhook.FeatureHelper$Companion.resolveMembers(FeatureHelper.kt:164)
I don't know if this is worth a BugReport on BugTracker, just wanted to let you know. The code is shared on Github: https://github.com/jaqxues/Akrolyb/blob/316b4b761c6e9b664141b68b951152b1bd805c89/akrolyb/src/main/java/com/jaqxues/akrolyb/genhook/FeatureHelper.kt#L163 Workaround:
Copy code
// fixme Explicit "Useless" Cast to Member. Kotlin will otherwise cast to Executable, which is only available in Oreo+
@Suppress("USELESS_CAST")
resolved[member] = when (member) {
    is MethodDec -> member.findMethod(resolvedClass) as Member
    is ConstructorDec -> member.findConstructor(resolvedClass) as Member
}
z
You might get a better response in #C0B8M7BUY
j
@Zach Klippenstein (he/him) [MOD] i was thinking about that, but this is more about the Kotlin compiler itself and not really about android. I just want to know if i should open an issue on YouTrack
or if this is a known issue / a WontFix