本地崩溃导致随机测试失败

7

我正在模拟器上运行我的应用程序的Espresso测试套件。我看到以下logcat输出的随机崩溃:

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/...)

这些崩溃是在大约300个测试用例的集合中随机发生的。 以下是我认为与此相关的app build.gradle文件的部分。 (此外,这些崩溃出现是在将gradle从“2.1.2”迁移到“3.1.1”之后开始出现的)。同时添加了项目依赖项。

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'
    }
}

1
你能发布你的app:gradle吗?它似乎与本地库存在冲突。也许你有一些版本不匹配? - Luís Henriques
添加了 Gradle 代码片段,我认为可能与此相关。 - mesh
你能同时发布“依赖项”部分吗?到目前为止一切都看起来很好。 - Luís Henriques
添加了@LuísHenriques - mesh
你是否检查过所有依赖项是否已更新以匹配Gradle版本?此外,如果没有显示库版本号,则可能是其他问题的提示。 - not2qubit
显示剩余3条评论
2个回答

2
问题出在测试机上的 API 23 Intel Atom x86 模拟器(该测试机是相当旧的),当我将其替换为 API 23 Google API x86 模拟器,并将系统目录指向最新 SDK(27.1)中的系统镜像后,到目前为止我没有再次看到那个错误。
${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 &

0

感谢您包含了我所要求的内容。

这可能与你的问题无关,但是你应该使用“implementation”而不是“compile”,因为“compile”关键字已弃用。你也应该使用“androidTestImplementation”。也许这些与Gradle 3有些冲突?虽然可能性不大,但还是值得一试的。
尝试将以下内容添加到app:gradle中:
android {
...
testOptions { unitTests.all { // All the usual Gradle options. jvmArgs('-ea', '-noverify') } unitTests { returnDefaultValues = true } }
...
}
最后,尝试清理和重建项目。你也可以尝试手动删除Android Studio编译时创建的文件夹,但如果你不知道自己在做什么,那可能会有些冒险。我的想法是,可能存在一些旧的、无用的东西的残留物,它们正在与你现在拥有的东西产生冲突。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接