allure-framework / allure-android

Android library for generating instrumentation reports in Allure format
Other
66 stars 23 forks source link

Instrumentation run failed due to 'java.lang.NoClassDefFoundError' (API 19, Samsung SM-T116) #47

Closed imbirovsky closed 4 years ago

imbirovsky commented 4 years ago

Hello. I really look forward to your help. When Allure is turned off, the tests are successful. But not with Allure.

Testing started at 19:00 ...
03/04 19:00:43: Launching 'ArchiveTests' on samsung SM-T116.
Running tests

$ adb shell am instrument -w -r    -e debug false -e class 'ua.XXX.YYY.fullTests.tests.ArchiveTests' ua.XXX.YYY.test/io.qameta.allure.espresso.AllureAndroidRunner
Connected to process 20260 on device 'samsung-sm_t116-3100c265b5149300'.

Started running tests
Test running failed: Instrumentation run failed due to 'java.lang.NoClassDefFoundError'

build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-android-extensions'
apply plugin: "kotlin-allopen"
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion rootProject.properties.compileSdkVersion
    defaultConfig {
        applicationId "xxx"
        minSdkVersion rootProject.properties.minSdkVersion
        targetSdkVersion rootProject.properties.targetSdkVersion
        versionCode 111
        versionName "1.1.1"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
    }
    lintOptions {
        abortOnError false
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
//            minifyEnabled true
//            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            ext.alwaysUpdateBuildId = false
        }
    }
    sourceSets {
        main {
            res.srcDirs = ['src/main/res',
                           'src/main/res-archive',
                           ...]
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    android {
        compileOptions {
            sourceCompatibility 1.8
            targetCompatibility 1.8
        }
    }
}
allOpen {
    annotation("sss.ddd.utils.OpenForTest")
}
dependencies {
    implementation project(':kkk')
    implementation project(':jjj')
    implementation project(':hhh')
    implementation project(':ggg')
    implementation "com.crashlytics.sdk.android:crashlytics:$rootProject.properties.crashlyticsVersion"
    implementation "androidx.multidex:multidex:$rootProject.properties.multiDexVersion"
    //room
    implementation "androidx.room:room-runtime:$rootProject.properties.roomVersion"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    kapt "androidx.room:room-compiler:$rootProject.properties.roomVersion"
    implementation "androidx.browser:browser:$rootProject.properties.browserVersion"
    implementation "androidx.constraintlayout:constraintlayout:$rootProject.properties.constraintlayoutVersion"
    implementation "androidx.recyclerview:recyclerview:$rootProject.properties.recyclerviewVersion"
    implementation "com.google.firebase:firebase-ml-vision:$rootProject.properties.firebaseMlVisionVersion"
    implementation "com.journeyapps:zxing-android-embedded:$rootProject.properties.zxingVersion"
    implementation "com.google.zxing:core:$rootProject.properties.zxingVersion"
    implementation "com.google.android.material:material:$rootProject.properties.materialVersion"
    implementation project(':lll')
    implementation project(':mmm')
    implementation project(path: ':nnn')
    testImplementation "com.squareup.okhttp3:mockwebserver:$rootProject.properties.okHttpVersion"
    testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:$rootProject.properties.mockitokotlinVersion"
    implementation project(':vvv')
    implementation("com.github.bumptech.glide:glide:$rootProject.properties.glideVersion") {
        exclude group: "com.android.support"
    }
    testImplementation 'org.json:json:20180130'
    testImplementation "androidx.arch.core:core-testing:$rootProject.properties.coreTestingVersion"
    implementation project(':qqq')
    implementation project(path: ':www')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation project(':ggg')
    implementation project(':fff')
    implementation project(':ddd')
    implementation project(':aaa')
    implementation project(':sss')
    implementation project(':xxx')
    implementation "androidx.exifinterface:exifinterface:$rootProject.properties.exifinterfaceVersion"
    implementation "com.google.android.gms:play-services-maps:$rootProject.properties.googleGmsPlayServicesMapsVersion"
    implementation "com.google.maps.android:android-maps-utils:$rootProject.properties.mapUtils"
    testImplementation "org.powermock:powermock-api-mockito2:$rootProject.properties.powerMockApiMokito2Version"
    testImplementation "org.powermock:powermock-core:$rootProject.properties.powerMockVersion"
    testImplementation "org.powermock:powermock-module-junit4:$rootProject.properties.powerMockVersion"
    implementation "com.airbnb.android:lottie:$rootProject.properties.lottie"
    testImplementation "io.mockk:mockk:$rootProject.properties.mockk"
}
}
... 
repositories {
    mavenCentral()
}
// FOR TESTING
android {
    defaultConfig {
        testInstrumentationRunner "io.qameta.allure.espresso.AllureAndroidRunner"
    }
    sourceSets {
        androidTest {
            assets.srcDirs = ['src/androidTest/assets/']
            res.srcDirs = ['src/androidTest/res']
        }
        debug {
            res.srcDirs = ['src/androidTest/res']
        }
    }
}
repositories {
    jcenter()
    maven { url 'https://dl.bintray.com/qameta/maven' }
}
dependencies {
    androidTestImplementation "junit:junit:$rootProject.properties.jUnitVersion"
    androidTestImplementation "io.qameta.allure:allure-android-commons:$rootProject.properties.allureRunnerVersion"
    androidTestImplementation "io.qameta.allure:allure-android-model:$rootProject.properties.allureRunnerVersion"
    androidTestImplementation "io.qameta.allure:allure-espresso:$rootProject.properties.allureRunnerVersion"
    androidTestImplementation "androidx.test.uiautomator:uiautomator:$rootProject.properties.uiAutomatorVersion"
    implementation 'androidx.annotation:annotation:1.1.0'
    androidTestUtil "androidx.test:orchestrator:$rootProject.properties.testOrchestrator"
    androidTestImplementation("androidx.test:rules:$rootProject.properties.testRulesVersion")
    androidTestImplementation("androidx.test:core:$rootProject.properties.testCore") {
        exclude group: 'javax.inject'
    }
    androidTestImplementation("androidx.test.espresso:espresso-contrib:$rootProject.properties.espressoCoreVersion")
    androidTestImplementation("androidx.test.espresso:espresso-web:$rootProject.properties.espressoCoreVersion")
    androidTestImplementation("androidx.test.espresso.idling:idling-concurrent:$rootProject.properties.espressoCoreVersion")
    androidTestImplementation("androidx.test.espresso:espresso-idling-resource:$rootProject.properties.espressoCoreVersion")
    androidTestImplementation("androidx.test.espresso:espresso-intents:$rootProject.properties.espressoCoreVersion")
}

build.gradle (module):

buildscript {
    ext.kotlin_version = '1.3.11'
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
        classpath 'com.google.gms:google-services:3.2.0'
        classpath 'io.fabric.tools:gradle:1.31.2'
    }
}
allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
        maven { url "https://jitpack.io" }
        mavenCentral() 
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}
ext {
    // sdk and tools
    compileSdkVersion = 28
    minSdkVersion = 16
    targetSdkVersion = 28
    multiDexVersion = '2.0.1'
    ...
    // for testing
    jUnitVersion = '4.12'
    espressoCoreVersion = "3.2.0"
    testRunner = "1.1.0"
    testRulesVersion = "1.1.0"
    coreTestingVersion = "2.0.0-beta01"
    testOrchestrator = "1.2.0"
    testCore = "1.2.0"
    uiAutomatorVersion = '2.2.0'
    allureRunnerVersion = '2.0.0'
    allureVersion = '2.8.1'
}

I tried it with <uses-sdk tools:overrideLibrary="android_libs.ub_uiautomator"/> and without <uses-sdk tools:overrideLibrary="android_libs.ub_uiautomator"/> in AndroidManifest.xml

I really look forward to your help 😞

imbirovsky commented 4 years ago

The launch of tests on API above 21 is successful.

Badya commented 4 years ago

@imbirovsky, it will be really helpful to have full stacktrace of Test running failed: Instrumentation run failed due to 'java.lang.NoClassDefFoundError' or full device logs of the failed run.

imbirovsky commented 4 years ago

Unfortunately, I don't know how to get the full stacktrace. When launching through the terminal, I see such an error:

$ adb shell am instrument -w -r    -e debug false -e class 'qq.xxx.zzz.fullTests.tests.StatementsTests' qq.xxx.zzz.test/io.qameta.allure.espresso.AllureAndroidRunner
INSTRUMENTATION_RESULT: shortMsg=java.lang.NoClassDefFoundError
INSTRUMENTATION_RESULT: longMsg=java.lang.NoClassDefFoundError: io.qameta.allure.android.io.FileSystemResultsReader
INSTRUMENTATION_CODE: 0
Badya commented 4 years ago

Seems you need to use in build.gradle:

testInstrumentationRunner "io.qameta.allure.espresso.MultiDexAllureAndroidRunner"
imbirovsky commented 4 years ago

Seems you need to use in build.gradle:

testInstrumentationRunner "io.qameta.allure.espresso.MultiDexAllureAndroidRunner"

Thanks a lot!