Detox: Conflict with dependency 'org.jetbrains.kotlin:kotlin-stdlib' in project ':app'.

Created on 5 Apr 2019  路  27Comments  路  Source: wix/Detox

Describe the bug
After following the documented guide for adding Android and trying to execute
detox build -c android.emu.debug
I get the following error.

FAILURE: Build failed with an exception.

Expected behavior
The build to be successful and run tests on Android.

Steps taken
I tried updating
ext.kotlinVersion = '1.3.0'
to 1.1.60 but that runs into error,

Could not find org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.1.60.

Environment (please complete the following information):

Device and Verbose Detox Logs
androidDependencies output.
*I noticed

org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.60@jar

and

org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.0@jar

and suspect that is the root cause of the error but lack the knowledge to figure out how to solve it.

https://gist.github.com/JanithaR/c5c7b3be1ce6b26ca3e66feb7937c94c

acceptebug android

All 27 comments

@d4vidi This is what I feared. We had similar stuff with Swift in iOS.

@JanithaR Please be sure to align detoxKotlinVersion with your app's version (1.1.60). Use this guide for reference.

I did and I have put the outcome in my bug report.

i have same error for this, i flow https://github.com/wix/Detox/blob/master/docs/Introduction.Android.md#3-add-kotlin this guide set kotlin version is 1.3.0, but have same error

i found this in react-native

Guys, does anyone have a suggestion/workaround to get tests running on Android for the time being?

@d4vidi

@JanithaR Please try adding this to your app's (i.e. root build.gradle) classpath:

    dependencies {
// ...
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
    }

@JanithaR last but not least, if all else fails please see whether your app declares org.jetbrains.kotlin:kotlin-stdlib a direct dependency. If so, please try switch it to org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.0 so as to align with detox.
Currently, detox declares it a hard dependency. Perhaps I ought to allow for this to be conditional but that will take a few days to work out.

for react native please remove

support Jetpack

android.useAndroidX=true
android.enableJetifier=true

from android/gradle.properties then work, i try this only for me

@JanithaR Please try adding this to your app's (i.e. root build.gradle) classpath:

    dependencies {
// ...
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
    }

I have already done this.

for react native please remove

support Jetpack

android.useAndroidX=true
android.enableJetifier=true

from android/gradle.properties then work, i try this only for me

I do not have these defined in my android/gradle.properties file.

In an effort to understand how things should be configured more correctly I cloned the repo and tried to get the demo-react-native-jest project provided in the example to get to work. That also ends up in an error.

> Task :app:compileDebugAndroidTestJavaWithJavac FAILED
/Users/janithar/Desktop/Repos/Detox/examples/demo-react-native-jest/android/app/src/androidTest/java/com/demoreactnativejest/DetoxTest.java:26: error: incompatible types: android.support.test.rule.ActivityTestRule<MainActivity> cannot be converted to androidx.test.rule.ActivityTestRule
        Detox.runTests(mActivityRule);

for react native please remove

support Jetpack

android.useAndroidX=true
android.enableJetifier=true
from android/gradle.properties then work, i try this only for me

I do not have these defined in my android/gradle.properties file.

can you share some you config?

../android/app/build.gradle

defaultConfig {
         ...
+        testBuildType System.getProperty('testBuildType', 'debug')
+        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
     }
...
dependencies {
     ...
+    androidTestImplementation(project(path: ":detox"))
+    androidTestImplementation 'junit:junit:4.12'
 }

.../DetoxTest.java

+package facilit.net.mobile;
+
+import com.wix.detox.Detox;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.LargeTest;
+import androidx.test.rule.ActivityTestRule;
+
+@RunWith(AndroidJUnit4.class)
+@LargeTest
+public class DetoxTest {
+
+    @Rule
+    public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false);
+
+    @Test
+    public void runDetoxTests() {
+        Detox.runTests(mActivityRule);
+    }
+}

.../android/build.gradle

buildscript {
     repositories {
         jcenter()
         google()
     }
+    
+    ext.kotlinVersion = '1.3.0'
+    ext.detoxKotlinVersion = ext.kotlinVersion
+
     dependencies {
         classpath 'com.android.tools.build:gradle:3.1.3'
-
+        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files
     }

../android/settings.gradle

+include ':detox'
+project(':detox').projectDir = new File(rootProject.projectDir, '../node_modules/detox/android/detox')

../package.json

"detox": {
     "configurations": {
       ...
+      "android.emu.debug": {
+        "binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
+        "build": "export ENVFILE=.env.beta && cd android && ./gradlew assembleBetaDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
+        "type": "android.emulator",
+        "name": "Nexus_5X_API_28"
       }
     },
...

.../gradle.properties

android.useDeprecatedNdk=true
FDVU_RELEASE_STORE_FILE=-
FDVU_RELEASE_KEY_ALIAS=-
FDVU_RELEASE_STORE_PASSWORD=-
FDVU_RELEASE_KEY_PASSWORD=-
android.enableAapt2=false
org.gradle.jvmargs=-Xmx1536M

@JanithaR sorry, the jest demo project happened to have been broken. I've just finished fixing it. You can use the other (mocha) demo project if you like.

What about this, though? https://github.com/wix/Detox/issues/1257#issuecomment-482087911

What about this, though? #1257 (comment)

Here are all the dependencies from .../android/app/build.gradle

dependencies {
    compile project(':react-native-gesture-handler')
    compile project(':react-native-device-info')
    implementation (project(':react-native-maps')){
       exclude group: 'com.google.android.gms', module: 'play-services-base'
       exclude group: 'com.google.android.gms', module: 'play-services-maps'
    }
    implementation 'com.google.android.gms:play-services-base:15.0.1'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    compile project(':rn-fetch-blob')
    compile project(':pushwoosh-react-native-plugin')
    compile (project(':react-native-camera')) {
        exclude group: "com.android.support"
    }
    compile project(':react-native-keychain')
    compile project(':react-native-background-upload')
    compile project(':react-native-image-picker')
    compile project(':react-native-config')
    compile project(':react-native-vector-icons')
    compile project(':react-native-i18n')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:27.1.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
    androidTestImplementation(project(path: ":detox"))
    androidTestImplementation 'junit:junit:4.12'
}

If I'm not terribly mistaken, org.jetbrains.kotlin:kotlin-stdlib is not a direct dependency.

EDIT:
I just realized that my previous gist was for 'androidDependencies' and it's not very clear. So I executed ./gradlew app:dependencies and got this output (gist). So the problem clearly lies in

project :pushwoosh-react-native-plugin

as that's where the dependency comes from. Following is the /node_modules/pushwoosh-react-native-plugin/src/android/build.gradle

buildscript {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.google.gms:google-services:4.2.0'
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

apply plugin: 'com.android.library'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.2"
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 27
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

ext {
    pushwoosh = "5.13.2"
}

evaluationDependsOn(':app')

rootProject.subprojects {
    if (name == "app") {
        if (!plugins.hasPlugin('com.google.gms.google-services')) {
            apply {
                plugin com.google.gms.googleservices.GoogleServicesPlugin
            }
        }
    }
}

dependencies {
    implementation 'com.facebook.react:react-native:+'
    implementation "com.pushwoosh:pushwoosh:${pushwoosh}"
    implementation "com.pushwoosh:pushwoosh-amazon:${pushwoosh}"
    implementation "com.pushwoosh:pushwoosh-badge:${pushwoosh}"
    implementation "com.pushwoosh:pushwoosh-inbox:${pushwoosh}"
    implementation "com.pushwoosh:pushwoosh-inbox-ui:${pushwoosh}"
    implementation "com.android.support:appcompat-v7:27.+"
    implementation "com.android.support:recyclerview-v7:27.+"
    api "com.android.support:design:27.+"
    implementation "com.android.support.constraint:constraint-layout:1.0.2"
    implementation "com.github.bumptech.glide:glide:4.7.1"
    **implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.60"**
    implementation "com.google.firebase:firebase-core:+"
    implementation "com.google.firebase:firebase-messaging:+"
}

I don't want to do anything here but I'm just gonna change the version and see if things start to work.

Aaand things are working after I updated /node_modules/pushwoosh-react-native-plugin/src/android/build.gradle dependency from implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.60" to implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.0".

I do not think that this is a smart solution. Can I force all transitive dependencies to be using the same version across all modules?

ahh kudos for that!

Yes, try this:

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.0"
implementation(project(':pushwoosh-react-native-plugin')) {
       exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk7'
}

Ok, thanks. I will definitely try that tomorrow.

While my problem is solved by resorting to a workaround I guess still there's something could be done that's way better. Really wish I could help you guys but I need a better understanding on how these dependencies work. Perhaps update the docs highlighting this issue and mention the same steps I took to rectify it until you guys come up with a solution to this accepted/bug?

@JanithaR With detox, we were trying to not force library users to introduce kotlin into their projects if they don't wish to. This is why we have the kotlin-stdlib-jdk declared as a dependency. Now it turns out that, though ironic, we could have made it difficult for projects that _are_ already using kotlin - such as your own. I think the solution here is to cleverly make this dep conditional.

@JanithaR has any of my suggestions worked out for you?

@JanithaR has any of my suggestions worked out for you?

Hey, sorry I live in Sri Lanka. You might've heard the terrible news by now. I didn't have time to code. Will get back.

Yes, of course. Terrible news. Wish you guys all the best.

Hi @JanithaR. I hope you are doing fairly well, given the situation.
In any case, if it matters for anything at all, I've formalized our discussion into a 'troubleshooting' subsection in the android guide. In any case, generally speaking things should be easier to work with starting Detox 12.6.3, so it would be best if you migrate. In essence, you don't need to define detoxKotlinVersion anymore. I'd appreciate feedback as to whether this has helped solving this issue.
Thanks

Solved (at least in theory) in 12.6.3 - closing this.

Was this page helpful?
0 / 5 - 0 ratings