DaggerMock icon indicating copy to clipboard operation
DaggerMock copied to clipboard

DaggerMock on multidex apps

Open sergiomarqmoura opened this issue 9 years ago • 8 comments

Hi again,

I am trying to apply DaggerMock to espresso UI tests on a multidex-enabled app, and it is giving a ClassDefNotFoundException on the "javax.inspect.Named" class. By setting up a traditional espresso + dagger testing architecture it is running well. However, we would love to use DaggerMock on this so that we could simplify it much.

Have you tested DaggerMock on multidex-enabled apps ?

sergiomarqmoura avatar Mar 15 '16 16:03 sergiomarqmoura

Hi, thanks for your report. No, I haven't tested it yet on a multidex app, fortunately I am not using it in the app I am working on. And right now DaggerMock is a Java module, it doesn't contains any reference to Android. Is this a common problem in multidex apps? Do you know if there is a solution to this problems?

fabioCollini avatar Mar 16 '16 22:03 fabioCollini

Hi,

Yes, multidex-enabled apps must be tested slightly different in UI testing cases. Concretely, developers must implement a custom multidex-ready test runner to replace the AndroidJUnitRunner on the build.gradle file. Check this: http://developer.android.com/tools/building/multidex.html#testing

Right now I am using a regular dagger configuration and a multidex test runner. However, this requires me to write a lot of code to set up the dependency injection correctly, and that's why I was trying to use DaggerMock. Anyway, really nice tool!

sergiomarqmoura avatar Mar 17 '16 10:03 sergiomarqmoura

Can you help me to reproduce the error? I created a new branch https://github.com/fabioCollini/DaggerMock/tree/multidex, I added many libs (finally Guava is helpful in an Android example!) and enabled multidex but I don't get any error on Android 6. Am I doing something wrong?

fabioCollini avatar Mar 17 '16 20:03 fabioCollini

Were there any updates on this issue? I am experiencing the same issue, also on a multidex android app.

csoon03 avatar Apr 21 '16 03:04 csoon03

I am sorry but I am not able to reproduce the error, I tried on this branch https://github.com/fabioCollini/DaggerMock/tree/multidex but it works. Can you help me to reproduce it? Are you using some different configuration?

fabioCollini avatar Apr 23 '16 17:04 fabioCollini

It has been a few projects ago since i last worked through multidex testing issues, so i may be slightly off base. As I recall when our test suite was throwing ClassDefNotFound errors it was always from hitting a critical mass of methods, and that particular build has a code path that ended up in the other dex file so could not be instrumented. It would rear its head at some random point in the development cycle, and something as simple as inlining a variable or changing workstations would change the dexed files enough that the tests would pass. Long story short it is hard to reproduce, or write a reliable test to instrument the issue.

EmmettWilson avatar Jan 26 '17 19:01 EmmettWilson

I would venture to say the issue is not with the library, and is related to the test runner that the user is running should support multidex applications.

EmmettWilson avatar Jan 26 '17 19:01 EmmettWilson

The javax.inspect.Named issue should be related to proguard.

By adding:

-dontwarn dagger.internal.codegen.**
-keepclassmembers,allowobfuscation class * {
   @javax.inject.* *;
   @dagger.* *;
   <init>();
}

-keep class dagger.* { *; }
-keep class javax.inject.* { *; }
-keep class * extends dagger.internal.Binding
-keep class * extends dagger.internal.ModuleAdapter
-keep class * extends dagger.internal.StaticInjection

to proguard-rules.pro the problem should be fixed.

ruigoncalo avatar Apr 21 '17 17:04 ruigoncalo