To reproduce the issue I'm facing I used the react-native example project demo-react-native from `Detox.
After installing the packages with yarn I executed the 2 commands to run the test:
1) cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release && cd ..
2) npx detox test -l error --configuration android.emu.release
So far everything works as expected but as soon I add the dependency of the Kotlin standard library in the android/app/build.gradle file like that
dependencies { ... androidTestImplementation('com.wix:detox:+') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.71" // <-- line added}and run the 2 steps again I get the following error
04-05 20:21:06.709 16552 16615 E AndroidRuntime: FATAL EXCEPTION: com.wix.detox.manager04-05 20:21:06.709 16552 16615 E AndroidRuntime: Process: com.test.app, PID: 1655204-05 20:21:06.709 16552 16615 E AndroidRuntime: java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/jvm/functions/Function1;04-05 20:21:06.709 16552 16615 E AndroidRuntime: at com.wix.detox.Detox$1.run(Detox.java:134)04-05 20:21:06.709 16552 16615 E AndroidRuntime: at java.lang.Thread.run(Thread.java:764)04-05 20:21:06.709 16552 16615 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "kotlin.jvm.functions.Function1" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/data/app/com.test.app.test-xbA2GW9WwS_BxzRNPa2waQ==/base.apk", zip file "/data/app/com.test.app-g_-tD026mxddTh82TmdYGg==/base.apk"],nativeLibraryDirectories=[/data/app/com.test.app.test-xbA2GW9WwS_BxzRNPa2waQ==/lib/x86, /data/app/com.test.app-g_-tD026mxddTh82TmdYGg==/lib/x86, /data/app/com.test.app.test-xbA2GW9WwS_BxzRNPa2waQ==/base.apk!/lib/x86, /data/app/com.test.app-g_-tD026mxddTh82TmdYGg==/base.apk!/lib/x86, /system/lib]]04-05 20:21:06.709 16552 16615 E AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)04-05 20:21:06.709 16552 16615 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:379)04-05 20:21:06.709 16552 16615 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:312)I have tried to load the JVM plugin in the android/build.gradle file as described here but it doesn't help.
What else can I do to make org.jetbrains.kotlin.jvm work in that project?
Thank you in advance.
Edit 1
I added kotlin.jvm.functions.Function1 to the MainApplication.java to test whether the Kotlin JVM is actually accessible by the project by adding the following code
...import kotlin.jvm.functions.Function0;import kotlin.jvm.functions.Function1;public class MainApplication extends Application implements ReactApplication { private Function1<Throwable, String> errorParseFn = new Function1<Throwable, String>() { @Override public String invoke(Throwable t) { return Log.getStackTraceString(t); } }; ... @Override public void onCreate() { super.onCreate(); SoLoader.init(this, /* native exopackage */ false); Log.d("@@@@@@", "onCreate"); Log.d("@@@@@@", errorParseFn.invoke(new Exception("Test Exception message"))); }}after I ran npx detox test -l error --configuration android.emu.release once again I could see the logs in the console.
04-06 21:24:06.715 23836 23836 D @@@@@@ : onCreate04-06 21:24:06.716 23836 23836 D @@@@@@ : java.lang.Exception: Test Exception message That means that the app itself has access to the kotlin.jvm, which means the gradle setup is correct.
Has anyone an idea how DetoxManager.java can access the Kotlin JVM at runtime?