7

I am running espresso test suite against my application on emulator. I see random crashes with following logcat output:

06-26 08:58:51.129  info    WebViewFactory  Loading com.android.webview version 44.0.2403.119 (code 246011960)
06-26 08:58:51.136  warn    System  ClassLoader referenced unknown path: /system/app/webview/lib/x86
06-26 08:58:51.139  info    LibraryLoader   Time to load native libraries: 1 ms (timestamps 9447-9448)
06-26 08:58:51.139  info    LibraryLoader   Expected native library version number "",actual native library version number ""
06-26 08:58:51.145  warn    art Attempt to remove non-JNI local reference, dumping thread
06-26 08:58:51.145  warn    art --------- beginning of crash
06-26 08:58:51.157  assert  libc    Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 23449 (myapp.com/...)

These crashes occur randomly against collection of around 300 test cases. Attaching portions of app build.gradle file which I think could be relevant. (Also, these crashes have started appearing after I migrated gradle from '2.1.2' to '3.1.1'). Added project dependencies as well.

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'

    defaultConfig {
        applicationId = BuildVars.applicationId
        minSdkVersion 21
        targetSdkVersion 23
        versionCode minutesSinceEpoch()
        versionName "${Version.packageVersion()}"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true

    }

    sourceSets.main {
        // use the jni .so compiled from the manual ndk-build command'''
        jniLibs.srcDirs = ['src/main/jniLibs/debug/lib', 'src/main/jniLibs/release/lib']
        jni.srcDirs = [] //disable automatic ndk-build call

    }

...

}

task ndkBuildDebug(type: Exec) {
    dependsOn swigBuild
    dependsOn getAndroidNdk
    dependsOn getAndroidAvd

    def ndkDir = PropertiesFile.getValue(project.localProperties, "ndk.dir")
    println "Your NDK appears to be in " + ndkDir

    def numCompileThreads = numCompilationThreads()
    println "Compiling with " + numCompileThreads + " threads "
    commandLine Shell.getShellCommandLine("${ndkDir}/ndk-build -j ${numCompileThreads} -C src/main/jni NDK_DEBUG=1 " +
            "NDK_OUT=../../../build/intermediates/ndk/debug/obj NDK_LIBS_OUT=../jniLibs/debug/lib"
    )
}


spoon {
    noAnimations = true

    def envSerial = System.env['ANDROID_SERIAL'];
    if (envSerial) {
        devices = [envSerial];
    }
    if (project.hasProperty('spoonClassName')) {
        className = project.spoonClassName
    }
    if (project.hasProperty('spoonMethodName')) {
        methodName = project.spoonMethodName
    }
    debug = true
    adbTimeout = 10*60
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile("com.appX:appX-android:$serializableLibVersion") {
        transitive = false
    }
    compile("com.appX:appX-primogenitor:$serializableLibVersion") {
        transitive = false
    }
    compile("com.appX:appX-serialize-common:$serializableLibVersion") {
        transitive = false
    }

    compile "com.android.support:support-v13:27.1.0"
    compile "com.android.support:appcompat-v7:27.1.0"
    compile 'com.android.support:recyclerview-v7:27.1.0'
    compile 'com.android.support:cardview-v7:27.1.0'
    compile 'com.android.support:design:27.1.0'
    compile 'com.android.support:percent:27.1.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.google.android.gms:play-services-base:10.2.1'
    compile 'com.google.android.gms:play-services-analytics:10.2.1'
    compile 'com.google.android.gms:play-services-gcm:10.2.1'

    compile 'com.jakewharton:butterknife:8.1.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.1.0'
    compile 'com.jakewharton.timber:timber:3.1.0'
    compile 'com.squareup:otto:1.3.8'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.squareup.retrofit2:converter-gson:2.3.0'
    compile 'com.squareup.retrofit2:converter-jackson:2.0.0'
    compile 'com.squareup.retrofit2:converter-scalars:2.1.0'
    compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.6.1'
    compile 'com.google.code.gson:gson:2.6.2'


    compile 'com.squareup.okhttp3:okhttp:3.8.0'
    compile 'com.squareup.okhttp3:logging-interceptor:3.8.0'

    compile 'com.google.guava:guava:18.0'
    compile 'io.reactivex:rxandroid:1.2.1'
    compile 'io.reactivex.rxjava2:rxjava:2.1.0'

    compile 'commons-lang:commons-lang:2.6'
    compile 'org.slf4j:slf4j-api:1.7.13'
    compile 'com.melnykov:floatingactionbutton:1.3.0'
    compile 'net.danlew:android.joda:2.7.2'
    compile 'uk.co.chrisjenx:calligraphy:2.1.0'
    compile 'frankiesardo:icepick:3.2.0'
    compile 'com.mikhaellopez:circularimageview:3.0.2'

    api 'frankiesardo:icepick:3.2.0'
    compileOnly 'frankiesardo:icepick-processor:3.2.0'
    annotationProcessor 'frankiesardo:icepick-processor:3.2.0'

    compile('com.crashlytics.sdk.android:crashlytics:2.5.1@aar') {
        transitive = true;
    }


    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
        exclude module: 'support-annotations'
    }

    androidTestCompile('com.android.support.test.espresso:espresso-idling-resource:2.2.2') {
        exclude module: 'support-annotations'
    }

    androidTestCompile "com.squareup.spoon:spoon-client:2.0.0-SNAPSHOT" // For Spoon snapshot, until 2.0.0 is released

    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
    androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'design'
        exclude group: 'com.android.support', module: 'recyclerview-v7'
    }
}
AK42
  • 831
  • 7
  • 12
  • 1
    Can you post you app:gradle? It seems to be a conflict with the native labraries. Maybe you have some version mismatch? – Luís Henriques Jun 26 '18 at 11:19
  • Added gradle snippets which I think maybe relevant... – AK42 Jun 26 '18 at 11:40
  • Can you post the "dependencies" part as well? Everything seems to be fine so far. – Luís Henriques Jun 26 '18 at 11:50
  • added @LuísHenriques – AK42 Jun 26 '18 at 12:14
  • Have you checked that all your dependencies have been updated to match the Gradle version? In addition that there is **no** library version number shown, may be a hint that something else is wrong. – not2qubit Jun 29 '18 at 08:09
  • This seems like an issue with the emulator. Is the emulator itself crashing sometimes? I've been facing some weird behavior with the emulator recently. If the crashes are happening while the tests are running and there are tests that have successfully executed with webviews before the crashes happen, then this might not be a compilation issue. Compilation issues happen while building or the moment we start running the app but not after having the app run for good amount of time. Try running the test cases with real devices and see if crashes occur there as well. – ahasbini Jun 30 '18 at 23:48
  • Yes, the tests fail randomly on an osx jenkins slave with emulator with API level 23, I am now trying to run on an emulator with API 24. I don't see the same crashes on a local emulator with API 23 or API 24. – AK42 Jul 01 '18 at 09:11
  • I think the emulator doesn't crash though as subsequent tests pass - and it is not my app webview for the crash that I see - maybe it is google's webview that is crashing - – AK42 Jul 01 '18 at 09:32

2 Answers2

2

The problem was API 23 Intel Atom x86 emulator on test machine (which dated to quite some time back), when I replaced it with API 23 Google API x86 emulator "and" pointed the system directory to system image in latest SDK (27.1) I have not seen that error again so far.

${SDK_DIR}/tools/emulator -no-boot-anim -sysdir /Users/jenkins/build_tools/android-sdk-27.1/system-images/android-23/google_apis/x86_64 -avd Nexus_9_API_23 > /dev/null 2>&1 &
AK42
  • 831
  • 7
  • 12
0

Thanks for including what I asked.

  1. This might be irrelevant, but you should use "implementation" instead of "compile" as the compile keyword is deprecated. You should use "androidTestImplementation" as well. Maybe these cause some conflicts with Gradle 3? Probably not. It might be worth the shot, though.

  2. Try adding this inside app:gradle

    android {
    
    ...
    
        testOptions {
            unitTests.all {
                // All the usual Gradle options.
                jvmArgs('-ea', '-noverify')
            }
            unitTests {
                returnDefaultValues = true
            }
        }
    
    ...
    
    }
    
  3. And finally, try to clean and rebuild your project. You could also try to manually delete the folders Android Studio creates when compiling it, but that might be a little risky if you don't know what you're doing. My though process is that there might be some remenants of older, useless stuff that are causing conflicts with what you have now.

Luís Henriques
  • 546
  • 6
  • 20