Instrumentation run failed due to 'Process crashed.' after long tests execution

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 05:30:19

问题


I have about 700 tests to execute. When I run them all, there raised a crash

"Instrumentation run failed due to 'Process crashed.'" Check device logcat for details. Test running failed: Instrumentation run failed due to 'Process crashed.'

after some time of execution, about 10 minutes and ~360-370th executed test.

Logcat doesn't contain any information about this crash

It is applicable by running from Android Studio, from cmd (on PC and Mac). Device used - Samsung S3 on Android 4.1.1

build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 18
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.xxx.yyy"
        minSdkVersion 9
        targetSdkVersion 18

        testApplicationId "com.xxx.zzz"
        testInstrumentationRunner "android.test.InstrumentationTestRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }

    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }

    project.gradle.taskGraph.whenReady {
        connectedAndroidTestDebug  {
            ignoreFailures = true
        }
    }
}


repositories {
    // The local cache should be used first
    mavenLocal()

    jcenter()
    mavenCentral()
}

dependencies {
    compile 'junit:junit:4.12'

    compile fileTree(include: '*.jar', dir: 'libs')
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xxx.yyy"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.CAMERA.autoFocus" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    <application
        android:allowBackup="true"
        android:largeHeap="true"
        android:icon="@drawable/ic_launcher"

        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name="com.xxx.yyy.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <meta-data
            android:name="roboguice.annotations.packages"
            android:value="com.xxx"/>
        <meta-data
            android:name="roboguice.modules"
            android:value="com.xxx.yyy.MainModule"/>
    </application>

</manifest>

One more to add: on previous released of my code this crash is not happen, but I can't find what exactly change gave a crash.

Please help me with this issue, I'm trying to understand it over two weeks.


回答1:


I don't know if the problem is still actual for you, but I have encountered such problem myself. There was a bug in certain Android versions on Samsung devices: they didn't close file descriptors properly thus creating file descriptors leak. After 1028 descriptors are created - the process crashes.

http://code.google.com/p/android/issues/detail?id=32470

To avoid this I had to cut on the usage of HandlerThreads in my tests, and re-use them where possible. But the better solution would be to change the device, probably.




回答2:


Try to run instrumentation tests on a newer version of Android OS, like Android 5.1 (API 22) or above. Some older versions, like Android 4.1, would have crashes like this on the ARM emulator.

Or try updating the Gradle version used in your project. For example, Gradle 4.1 would have this problem, but gradle 4.10 should not.

Alternatively, try to avoid running tests in the background, where no Activity is launched. So avoid using ActivityUnitTestCase and SingleLaunchActivityTestCase which can cause a native C++ crash on Android 4.1. More info here: Native crash at /dev/ashmem/dalvik-jit-code-cache



来源:https://stackoverflow.com/questions/31917124/instrumentation-run-failed-due-to-process-crashed-after-long-tests-execution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!