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

Native Android: kotlin: Unresolved reference: Detox, config, DetoxConfig in DetoxTest.kt while building app. #3910

Closed
1 of 2 tasks
jstawow opened this issue Feb 2, 2023 · 5 comments

Comments

@jstawow
Copy link

jstawow commented Feb 2, 2023

What happened?

When i try run app by using npx detox build -c android.emu.debug --stacktrace, I encounter problem with references:
Detox, config, DetoxConfig in DetoxTest.kt.

I have added following changes:

app/build.gradle.kts:

plugins {
    id("com.android.application")
    id("com.google.gms.google-services")
    id("com.google.dagger.hilt.android")
    kotlin("kapt")
    kotlin("android")
    id("com.google.devtools.ksp") version "1.7.20-1.0.8"
}

android {
    namespace = "com.xxx.android"
    compileSdk = Deps.Sdk.compileSdk

    defaultConfig {
        applicationId = "com.xxx.android"
        minSdk = Deps.Sdk.minSdk
        targetSdk = Deps.Sdk.targetSdk
        versionCode = Deps.Sdk.versionCode
        versionName = Deps.Sdk.versionName

        testBuildType = System.getProperty("testBuildType", "debug")
        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true

    }

    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
    buildFeatures {
        compose = true
    }
    composeOptions {
        kotlinCompilerExtensionVersion = "1.3.2"
    }
    packagingOptions {
        resources.excludes.addAll(
            listOf(
                "/META-INF/{AL2.0,LGPL2.1}",
            )
        )
    }

    applicationVariants.all {
        kotlin.sourceSets {
            getByName(name) {
                kotlin.srcDir("build/generated/ksp/$name/kotlin")
            }
        }
    }
}

dependencies {
    implementation(project(":data"))
    implementation(project(":domain"))
    implementation(platform(Deps.composeBom))
    implementation(Deps.coreKtx)
    implementation(Deps.runtimeKtx)
    implementation(Deps.composeActivity)
    implementation(Deps.composeUiToolingPreview)
    implementation(Deps.composeMaterial3)
    implementation(Deps.composeViewModel)
    implementation(Deps.composeDestinations)
    implementation(Deps.composeLifecycleRuntime)
    implementation(platform(Deps.firebaseBom))
    implementation(Deps.hilt)
    implementation(Deps.hiltNavigationCompose)
    implementation(Deps.timber)
    kapt(Deps.hiltCompiler)
    testImplementation(Deps.junit)
    debugImplementation(Deps.composeUiTooling)
    debugImplementation(Deps.composeUiTestManifest)
    ksp(Deps.composeDestinationsKsp)
    androidTestImplementation(Deps.junit)
    implementation(Deps.appcompat)
    androidTestImplementation("androidx.test:core:1.5.0")
    androidTestImplementation("androidx.test:runner:1.5.2")
    androidTestImplementation("androidx.test:rules:1.5.0")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.ext:truth:1.5.0")
    androidTestImplementation( "androidx.test.espresso:espresso-core:3.5.1")
    androidTestImplementation( "androidx.test.espresso:espresso-contrib:3.5.1")
    androidTestImplementation( "androidx.test.espresso:espresso-intents:3.5.1")
    androidTestImplementation( "androidx.test.espresso:espresso-accessibility:3.5.1")
    androidTestImplementation( "androidx.test.espresso:espresso-web:3.5.1")
    androidTestImplementation( "androidx.test.espresso:espresso-idling-resource:3.5.1")
    androidTestImplementation( "androidx.test.espresso.idling:idling-concurrent:3.5.1")
    androidTestImplementation("com.wix:detox:+") {
       exclude(group = "org.jetbrains.kotlin", module = "GradleKotlinCompilerWorkAction")
   }
}

main/build.gradle.kts:

buildscript {

    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
        maven("../node_modules/detox/Detox-android") //detox is configured in ../root so node_modules is under path like specified in maven()
        maven("../node_modules/jsc-android/dist")
        maven("../node_modules/detox/Detox-android")
    }
    dependencies {
        classpath("com.google.gms:google-services:4.3.14")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20")
    }
}
plugins {
    id("com.android.application") version "7.3.1" apply false
    id("com.android.library") version "7.3.1" apply false
    // There is no updated Kotlin plugin for 1.7.21 yet
    id("org.jetbrains.kotlin.android") version "1.7.20" apply false
    id("org.jetbrains.kotlin.jvm") version "1.7.20" apply false
    // Currently there's an issue with Android Studio Dolphin | 2021.3.1 Patch 1, bump Hilt version when resolved
    id("com.google.dagger.hilt.android") version "2.42" apply false
}

app/src/androidTest/java/com/com.xxx.android/DetoxTest.kt

package com.xxx.android

import com.wix.detox.Detox
import com.wix.detox.config.DetoxConfig
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
class DetoxTest {
    @Rule // (2)
    var mActivityRule: ActivityTestRule<MainActivity> =
        ActivityTestRule(MainActivity::class.java, false, false)

    @Test
    fun runDetoxTests() {
        val detoxConfig = DetoxConfig()
        detoxConfig.idlePolicyConfig.masterTimeoutSec = 90
        detoxConfig.idlePolicyConfig.idleResourceTimeoutSec = 60
        detoxConfig.rnContextLoadTimeoutSec = if (com.xxx.android.BuildConfig.DEBUG) 180 else 60
        Detox.runTests(mActivityRule, detoxConfig)
    }
}

app/src/main/res/xml/network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">10.0.2.2</domain>
        <domain includeSubdomains="true">localhost</domain>
    </domain-config>
</network-security-config>

buildSrc/src/main/kotlin/Deps.kt

    const val detox = "com.wix:detox:+"
    const val appcompat = "androidx.appcompat:appcompat:1.1.0"

What i noticed also that:
i have not those classes in External Libraries, Gradle:com.wix:detox:0.1.1@aar in com.wix.detox module, I have imported detox like this import com.wix.detox.Detox
Zrzut ekranu 2023-02-2 o 15 19 28

Output:

npx detox build -c android.emu.debug --stacktrace
cd android ; ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug ; cd -

> Task :app:compileDebugAndroidTestKotlin FAILED
e: /Users/nname/Desktop/herearetests/android/app/src/androidTest/java/com/com.xxx.android/DetoxTest.kt: (3, 22): Unresolved reference: Detox
e: /Users/nname/Desktop/herearetests/android/app/src/androidTest/java/com/com.xxx.android/DetoxTest.kt: (4, 22): Unresolved reference: config
e: /Users/nname/Desktop/herearetests/android/app/src/androidTest/java/com/com.xxx.android/DetoxTest.kt: (21, 27): Unresolved reference: DetoxConfig
e: /Users/nname/Desktop/herearetests/android/app/src/androidTest/java/com/com.xxx.android/DetoxTest.kt: (22, 38): Variable expected
e: /Users/nname/Desktop/herearetests/android/app/src/androidTest/java/com/com.xxx.android/DetoxTest.kt: (23, 38): Variable expected
e: /Users/nname/Desktop/herearetests/android/app/src/androidTest/java/com/com.xxx.android/DetoxTest.kt: (24, 21): Variable expected
e: /Users/nname/Desktop/herearetests/android/app/src/androidTest/java/com/com.xxx.android/DetoxTest.kt: (25, 9): Unresolved reference: Detox

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugAndroidTestKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
132 actionable tasks: 1 executed, 131 up-to-date
/Users/nname/Desktop/xxx_detox
user@MacBook-Pro-Name xxx_detox %

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugAndroidTestKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details
<img width="690" alt="Zrzut ekranu 2023-02-2 o 15 41 53" src="https://user-images.githubusercontent.com/91880075/216355094-7251db72-3531-4fa3-8674-79562ea48284.png">

File structure:

What was the expected behaviour?

No response

Was it tested on latest Detox?

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

Did your test throw out a timeout?

Help us reproduce this issue!

No response

In what environment did this happen?

Detox version:
Kotlin:1.7.20
Node version: v14.17.6
Device model: Pixel XL API 28
Android version: 9
Test-runner (select one): jest

Detox logs

Detox logs
paste logs here!

Device logs

Device logs
paste logs here!

More data, please!

No response

@jstawow jstawow changed the title Native Android: kotlin: unresolved reference Unresolved reference: Detox, config, DetoxConfig in DetoxTest.kt while building app. Native Android: kotlin: Unresolved reference: Detox, config, DetoxConfig in DetoxTest.kt while building app. Feb 2, 2023
@stale
Copy link

stale bot commented Mar 14, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back.

Thank you for your contributions!

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

@stale stale bot added the 🏚 stale label Mar 14, 2023
@stale
Copy link

stale bot commented Mar 24, 2023

The issue has been closed for inactivity.

@stale stale bot closed this as completed Mar 24, 2023
@d4vidi
Copy link
Collaborator

d4vidi commented Mar 28, 2023

        maven("../node_modules/detox/Detox-android") //detox is configured in ../root so node_modules is under path like specified in maven()

This is likely the wrong path. Gradle would likely soft-fail over that.

In either case, try also applying that under an allprojects:
https://wix.github.io/Detox/docs/introduction/project-setup/#41-patching-build-scripts

@jstawow
Copy link
Author

jstawow commented Mar 29, 2023

it is not like detox does not work with android native application ??

@d4vidi
Copy link
Collaborator

d4vidi commented Mar 29, 2023

it is not like detox does not work with android native application ??

Oh geez. Thanks for pointing that out. You are perfectly right in that we don't properly support pure-native android and that I should stop working late nights 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants