Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassNotFoundException: Didn't find class "kotlin.jvm.functions.Function1" #1994

Closed
1 task done
thomas-coinjar opened this issue Apr 5, 2020 · 6 comments
Closed
1 task done

Comments

@thomas-coinjar
Copy link

thomas-coinjar commented Apr 5, 2020

Describe the bug
I created a release APK

  1. ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release

and installed it on an emulator. The app starts without a problem and logcat doesn't show any exceptions.

After that I started detox

  1. npx detox test -l error --configuration android.emu.debug

The app starts and the then crashes with the following error

04-05 20:21:06.709 16552 16615 E AndroidRuntime: FATAL EXCEPTION: com.wix.detox.manager
04-05 20:21:06.709 16552 16615 E AndroidRuntime: Process: com.test.app, PID: 16552
04-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)

To Reproduce

  • I have tested this issue on the latest Detox release and it still reproduces

Steps to reproduce:

  1. ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release
  2. npx detox test -l error --configuration android.emu.debug

android/build.gradle (truncated)

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 26
        compileSdkVersion = 26
        targetSdkVersion = 27
        supportLibVersion = "28.0.0"
        kotlinVersion = '1.3.41'
        reactNative = "0.61.5"
    }

    repositories {
        mavenCentral()
        mavenLocal()
        google()
        jcenter()
        maven {
            url 'https://jitpack.io'
        }
        maven {
            url 'https://maven.google.com'
            name 'Google'
        }
    }
    dependencies {
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'com.android.tools.build:gradle:3.6.1'
        classpath "com.android.support:appcompat-v7:28.0.0"
        classpath 'com.android.support:design:28.0.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
    }
}

allprojects {
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xlint:unchecked"
        }
    }
    repositories {
        mavenCentral()
        mavenLocal()
        google()
        jcenter()
        maven {
            url 'https://maven.google.com'
        }
        maven {
            url("$rootDir/../../node_modules/react-native/android")
        }
        maven {
            url("$rootDir/../../node_modules/detox/Detox-android")
        }
        maven {
            url("$rootDir/../../node_modules/jsc-android/dist")
        }
        maven { url 'https://jitpack.io' }
    }
}

android/app/build.gradle (truncated)

apply plugin: "com.android.application"
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

project.ext.react = [
    entryFile: "index.js",
    enableHermes: true,  // clean and rebuild if changing
    bundleInStaging: true,
    bundleInInternalTest: true,
    bundleInRelease: false
]
apply from: "../../../node_modules/react-native/react.gradle"

android {
  compileSdkVersion 28
  defaultConfig {
    applicationId "com.test.app"
    minSdkVersion 26
    targetSdkVersion 28
    multiDexEnabled true
    testBuildType System.getProperty('testBuildType', 'debug')
    testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
  }
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
  signingConfigs {..}
  splits {..}
  buildTypes {..}
  dexOptions{..}
  
}

repositories {
    mavenLocal()
    google()
    jcenter()
    maven { url "https://jitpack.io" }
    maven { url "https://maven.google.com" }
}

dependencies {
  implementation "com.facebook.react:react-native:0.61.5"
  androidTestImplementation('com.wix:detox:+') { 
    exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk7'
  }
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.41"
  androidTestImplementation 'androidx.test:runner:1.2.0'
  androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

configurations.all {
  resolutionStrategy {
    force 'androidx.annotation:annotation:1.0.0'
  }
}

apply plugin: 'com.google.gms.google-services'
apply from: file("../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle")

Expected behavior
I expected that the test will start

Screenshots
N/A

Device and Verbose Detox Logs
(see above)
no detox logs

Environment (please complete the following information):

  • Detox: 16.0.1
  • React Native: 0.61.5
  • Node: 12.8.0
  • Device: Pixel_2_API_28 emulator
  • OS: Android
  • Test-runner jest
"android.emu.debug": {
  "binaryPath": "android/app/build/outputs/apk/release/app-release.apk",
  "build": "cd android && RN_SRC_EXT=e2e.js ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release && cd ..",
  "type": "android.emulator",
  "device": {
    "avdName": "Nexus_6P_API_28"
  }
},
@support
Copy link

support bot commented Apr 5, 2020

We use the issue tracker exclusively for bug reports and feature requests. This issue appears to be a general usage or support question. Instead, please ask a question on Stack Overflow with the detox tag.

Feel free to post your Stack Overflow question here for more visibility. We'll take a look at it.

For issues with Expo apps, it is most likely not an issue with Detox itself, but with the Expo runtime or with incorrect Detox setup. For support on how to use Detox with Expo, you should contact the Expo team or the Expo community.

For more information on bots in this repository, read this discussion.

@support support bot closed this as completed Apr 5, 2020
@d4vidi
Copy link
Collaborator

d4vidi commented Apr 5, 2020

@thomas-coinjar please post this on SO and paste a ref here 🙏

@thomas-coinjar
Copy link
Author

thomas-coinjar commented Apr 6, 2020

Hi @d4vidi,

I get why you believe that I should post the problem on SO but I still think it's a real problem. Here the reason why:

In the official guide how to add Kotlin to the Android Studio project it states that the below code must be added to the module gradle file. For RN it means android/app/build.gradle

apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

...

dependencies {
   implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

So, if I add the line implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.41" to the app/build.gradle of Detox's example app examples/demo-react-native I get exactly the same error, when I try to run detox test.

Please keep in mind other third party RN libraries need Kotlin to work.

@d4vidi
Copy link
Collaborator

d4vidi commented Apr 6, 2020

It seems that with Detox we now require kotlin-stdlib-jdk8 rather than kotlin-stdlib-jdk7. Can you consider upgrading? Your source compatibility is for java 1.8 anyways.
Last but not least, consider renaming android.emu.debug to android.emu.release :)

@thomas-coinjar
Copy link
Author

thomas-coinjar commented Apr 6, 2020

Hi @d4vidi,

Yes I have already upgraded the version to kotlin-stdlib-jdk8 but I'm totally stuck here. One of the libraries we are using is react-native-webview, which uses the standard Kotlin library. This package is crashing the app when I start the Detox run because DetoxManager.java can't find the JVM.

I have reached out to SO but no response yet.

It seems the project examples/demo-react-native itself has access to the JVM though. I confirmed that by adding the code below to MainApplication

...
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")));
    }
}

I can clearly see the log in the console

04-06 21:24:06.715 23836 23836 D @@@@@@  : onCreate
04-06 21:24:06.716 23836 23836 D @@@@@@  : java.lang.Exception: Test Exception message

Nevertheless DetoxManager.java can not find the class at runtime but it was there at compile time. Hence the NoClassDefFoundError.

Not sure what to do from here.

@thomas-coinjar
Copy link
Author

thomas-coinjar commented Apr 9, 2020

Hi @d4vidi,

I finally found out that ProGuard is deleting the kotlin files. I will disable it for E2E.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants