diffuse
diffuse copied to clipboard
Looking for replacement of dex-member-list
I have this dependency:
testImplementation("com.jakewharton.dex:dex-member-list:4.1.1")
and I'm getting an exception when calling from Kotlin (at 1.4.32)
I'm using this code
fun dexMethod(className: String, methodName: String): Matcher<DexMethod> =
object : TypeSafeMatcher<DexMethod>() {
override fun describeTo(description: Description): Unit = with(description) {
appendText("method ").appendValue(methodName)
appendText(" ")
appendText("in class ").appendValue(className)
}
override fun matchesSafely(item: DexMethod) =
className == item.declaringType.sourceName && methodName == item.name
}
and getting this exception
java.lang.NoSuchMethodError: com.jakewharton.dex.DexMethod.getDeclaringType-YNYzXYw()Ljava/lang/String;
at net.twisterrob.gradle.android.GradleTestHelpersKt$dexMethod$1.matchesSafely(GradleTestHelpers.kt:184)
I tried using "-Xuse-14-inline-classes-mangling-scheme", but no luck.
So far I've spent 3 hours of deep hacking around on this, and couldn't find a way to do it. I managed to write a reflective hack in Java after I understood the issue, but it would be easier to upgrade to a newer version of the library, is diffuse available from maven?
@Override
protected boolean matchesSafely(DexMethod item) {
return className.equals(sourceName(item.getDeclaringType())) && methodName.equals(item.getName());
}
String sourceName(String declaringType) {
try {
Method sourceName = TypeDescriptor.class.getDeclaredMethod("getSourceName-impl", String.class);
sourceName.setAccessible(true);
return (String)sourceName.invoke(null, declaringType);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
}
Yes I will work on publishing this week.