2

My app has following appsflyer dependencies:

'com.appsflyer:af-android-sdk:4.8.15' 'com.android.installreferrer:installreferrer:1.0'

And, I have tried running Robolectric unit test with appsflyer dependency added, but my test did not start but just throws an error, which is below(I can run the test and test succeeds if I remove the appsflyer dependency.)

java.lang.NoClassDefFoundError: com/appsflyer/r (wrong name: com/appsflyer/R)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.lang.ClassLoader.defineClass(ClassLoader.java:642)
at org.robolectric.internal.bytecode.SandboxClassLoader.maybeInstrumentClass(SandboxClassLoader.java:134)
at org.robolectric.internal.bytecode.SandboxClassLoader.lambda$findClass$0(SandboxClassLoader.java:111)
at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:50)
at org.robolectric.internal.bytecode.SandboxClassLoader.findClass(SandboxClassLoader.java:110)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.appsflyer.AppsFlyerLib.<init>(:176)
at com.appsflyer.AppsFlyerLib.<clinit>(:162)
at ... org.robolectric.android.internal.ParallelUniverse.lambda$setUpApplicationState$0(ParallelUniverse.java:260)
at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:72)
at org.robolectric.android.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:260)
at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:377)
at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:252)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:130)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:42)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:84)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:104)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131) [Robolectric] jp.co.matchingagent.cocotsure.ui.contact.ContactActionCreatorTest.loadMoreNewMatchRoomListTest exist data: sdk=27; resources=legacy [Robolectric] NOTICE: legacy resources mode is deprecated; see http://robolectric.org/migrating/#migrating-to-40java.lang.IllegalStateException: this method should only be called by Robolectric at org.robolectric.shadows.ShadowDisplayManager.configureDefaultDisplay(ShadowDisplayManager.java:43)
at org.robolectric.android.Bootstrap.setUpDisplay(Bootstrap.java:18)
at org.robolectric.android.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:194)
at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:377)
at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:252)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:130)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:42)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:84)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:104)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)

Thanks in advance!

shoheikawano
  • 1,092
  • 3
  • 14
  • 31
  • according to `java.lang.NoClassDefFoundError: com/appsflyer/r (wrong name: com/appsflyer/R)`, it looks the library version issue. – shizhen Nov 29 '18 at 08:17
  • @shizhen thank you for your comment. Do you mean if I specify the different library version for appsflyer library it will solve the problem? I tried it but it did not. – shoheikawano Nov 29 '18 at 09:15
  • can post your complete dependency configuration in `build.gradle`? – shizhen Nov 29 '18 at 09:21
  • **NoClassDefFoundError** is an error that occurs when a particular class is present at compile time, but was missing at run time. Check your gradle build configuration for `com/appsflyer/r` is correct. – shizhen Nov 29 '18 at 09:31
  • > Check your gradle build configuration for com/appsflyer/r is correct. Does it mean I need to configure something on build.gradle specifically for appsflyer when testing? – shoheikawano Dec 03 '18 at 04:10
  • I am assuming that multi-module structure may relate to this issue? – shoheikawano Dec 03 '18 at 04:11
  • 1
    Updating the appsflyer library version seems resolved the issue. – shoheikawano Feb 26 '19 at 04:40

1 Answers1

2

Fixed from AppsFlyer version 4.8.19

k4dima
  • 6,070
  • 5
  • 41
  • 39