Appium server 1.19.1 - still getting lifecycleEventObserver error when using Espresso driver

Hello. I’m stuck for days trying to simply launch an app using Espresso driver with Appium. I’m on a Kotlin \ Gradle project, using appium 7.4.1 and server 1.19.1. I’m on Windows 10. Android SDK Tools and Emulator are up to date and java version is 8
Here’s the log:

espresso_driver_erro1.txt (27.5 KB)

Just a note, I’ve come across many other problems like signature which I found the solution, but now I’m stuck for real. I also checked the other issues here about this problem and that couldn’t help me either. Using UiAutomator2 works fine

do you use proguard?

The project that generates the .apk uses proguard, but I commented the following code of its build.gradle and regenerated the .apk:

    buildTypes {
        debug {
            testCoverageEnabled true
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

Then I ran again and got the same problem

I assume there is a conflict between module versions. lifecycleEventObserver has been added since version 2.0.0 of the component (https://developer.android.com/jetpack/androidx/releases/lifecycle). Perhaps your app uses an older version of the module, which overrides the one needed by Espresso server.

OK so I created a new android app with the following config in gradle, everything is up to date:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "br.com.zup.beagle.appiumApp"
        minSdkVersion 30
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled 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'
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.4.20"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation project(Dependencies.Modules.core)
}

I generated the .apk, cleaned the device and runned my Appium project again. Got the same error espresso_driver_erro2.txt (26.8 KB)

The androidx.lifecycle version is 2.2.0 is the .apk
You mentioned a different version conflict. Where else can I look for to find another androidx.lifecycle version and compare?

I would check the full dependency tree: https://stackoverflow.com/questions/21645071/using-gradle-to-find-dependency-tree

Perhaps, there are some implicit transitive deps

I got the dependency tree but I’m still clueless as what the problem is. I’m attaching the dependency tree report. Bear in mind, the app code is fresh, it has an empty main activity. It was created using Android Studio template. No business logic or third party code was added afterwards. All the dependencies were set by Android Studio. It’s hard to believe the problem is with the app.
dependency_tree.txt (123.8 KB)

app’s build.gradle file:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.example.sampleApp"
        minSdkVersion 30
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

//    buildTypes {
//        release {
//            minifyEnabled 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'
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

Version 2.1.0

Important changes since 2.0.0

  • Added LifecycleEventObserver for the cases when a stream of lifecycle events is needed. It is a public API instead of a hidden GenericLifecycleObserver class.

I see that Espresso components (in particular androidx.test.core) are using version 2.0.0 of the lifecycle component while others use 2.1.0 or 2.2.0. Consider downgrading these that use the newer version. You could also try to mark this dependency as transitive=false for Espresso itself and see if that helps

Thanks for the help so far.

As for the dependencies, where do you think the LifecycleEventObserver is being imported? There’s no ‘androidx.lifecycle’ dependency in the fresh app

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

Check the dependency tree above, the package name is androidx.lifecycle:lifecycle-common

Alright, so I tested separately a bunch of alternatives on the .apk project and none of them worked (it gave me the same error). Here’s what I did:

  1. added transitive = false notation for espresso dependency
androidTestImplementation ('androidx.test.espresso:espresso-core:3.3.0'){
        transitive=false
    }
  1. Updated espresso lib version
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0-alpha02'
  1. Remove the espresso dependency

  2. Downgraded androidx.core dependency

implementation 'androidx.core:core-ktx:1.1.0'

Since Espresso run tests work with the .apk project in Android Studio, I’m starting to assume it is a appium-espresso-driver problem.

If I open the same issue in GitHub’s appium-espresso-driver project, will it have a different analysis approach ?

Yes, for transitive dependencies you’d need to edit the Espresso’s gradle config. All sources are available locally on your machine as a part of appium module.

If I open the same issue in GitHub’s appium-espresso-driver project, will it have a different analysis approach ?

I assume yes.

Hi, I am having the same problem, did you find any solution ?

No. I open the issues here:

I have managed to fix my problem by adding this desired capability:
“espressoBuildConfig”: “{ “additionalAppDependencies”: [ “com.google.android.material:material:1.0.0”, “androidx.lifecycle:lifecycle-extensions:2.1.0” ] }”
}

Please, comment the workaround you found here:


thanks