0

I'm testing my :app module with a specific :test module.

The test module applies the com.android.test plugin and configures release to test the obfuscated release variant.

Now both modules use kotlin.Result and obfuscate it with the same name. The difference only is, that :test uses kotlin.Result$Companion while this type is completely striped from the :app APK.

The problem is, that the test code resolves the obfuscated class from the app dex file instead of looking it up in the test dex file, therefore the companion object is not found.

How do I make sure to load the correct classes in my test cases?

tynn
  • 38,113
  • 8
  • 108
  • 143
  • How do you know `kotlin.Result$Companion` was stripped from the `:app` module in the first place? In doubt, the best way to make sure you get a class from `:test` and not from `:app` is that they are named differently. But maybe you want to avoid that for some reason? – Victor Paléologue Nov 26 '21 at 14:14
  • @VictorPaléologue I had a look at the mappings. Both APK contained the obfuscated `kotlin.Result` named the same, but only `:test` contained the obfuscated`kotlin.Result$Companion` as well. I'm using the android test plugin, which requires the obfuscation to be enabled, but I couldn't find a configuration path to handle this case... for now my solution is not to use _Kotlin_ for the tests... – tynn Nov 26 '21 at 21:14
  • How about making your tests depend explicitly on the library that provides `kotlin.Result`? – Victor Paléologue Nov 27 '21 at 11:47
  • That's all fine. The problem is, that the class itself is looked up in the main apk, instead of the test apk. – tynn Nov 27 '21 at 19:38

0 Answers0