Android, JaCoco не может создать покрытие для "android.uid.system" - PullRequest
0 голосов
/ 17 января 2019

JaCoco не может создать отчет о покрытии для Инструментированных тестовых случаев при использовании android:sharedUserId="android.uid.system".

Но, если я изменю android:sharedUserId на значение, отличное от android.uid.system, тогда он генерирует надлежащие отчеты о покрытии.

Я использую com.android.tools.build:gradle:3.1.0

Мой AndroidManifest.xml выглядит следующим образом -

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

<!-- This causing problel, if I remove this line, then working fine--->
          android:sharedUserId="android.uid.system">

    <uses-sdk
            android:minSdkVersion="25"
            android:targetSdkVersion="25" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_ETHERNET_STATE" />
    <uses-permission android:name="android.permission.CHANGE_ETHERNET_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.SET_TIME" />
    <uses-permission android:name="android.permission.SET_TIME_ZONE" />
    <uses-permission android:name="android.permission.SHUTDOWN" />
    <uses-permission android:name="android.permission.REBOOT" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.DELETE_PACKAGES"/>
    <uses-permission android:name="android.permission.READ_LOGS"/>

    <application
            android:name=".CoreServiceApplication"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:persistent="true"
            tools:replace="android:icon,android:name">
        <receiver android:name=".BootReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

        <service
                android:name=".CoreServiceExecutor"
                android:exported="true" >
            <intent-filter>
                <action android:name="com.coreservices.START_SERVICE" />
            </intent-filter>
        </service>

        <service
                android:name=".logcat.dump.LogcatDumpService"
                android:process="com.coreservices.logcat.dump"
                android:exported="true" >
            <intent-filter>
                <action android:name="com.coreservices.logcat.DUMP" />
            </intent-filter>
        </service>

    </application>

</manifest>

Мой build.gradle выглядит следующим образом -

apply plugin: 'com.android.application'

android {
    defaultConfig {
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        debug {
            storeFile project.rootProject.file(RELEASE_STORE_FILE)
            storePassword RELEASE_STORE_PASSWORD
            keyAlias RELEASE_KEY_ALIAS
            keyPassword RELEASE_KEY_PASSWORD
        }
    }

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

        debug {
            testCoverageEnabled true
            signingConfig signingConfigs.debug
        }
    }
    sourceSets {
        main {
            java.srcDirs = ['src/']
            res.srcDirs = ['res/']
            assets.srcDir('assets/')
            manifest.srcFile 'AndroidManifest.xml'
        }
        androidTest {
            java.srcDirs = ['src-test/']
        }

        test {
            java.srcDirs = ['junitTest/']
        }
    }
}

dependencies {

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'

}
repositories {
    google()
    jcenter()
}
apply plugin: 'jacoco'

task jacocoTestReport(type: JacocoReport, dependsOn: [/*'testDebugUnitTest',*/ 'createDebugCoverageReport']) {

    reports {
        xml.enabled = true
        html.enabled = true
    }

    def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*',
                      '**/*Test*.*', 'android/**/*.*']

    def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter)

    def mainSrc = "${project.projectDir}/src"

    //Explain to JaCoco where is our source code
    sourceDirectories = files([mainSrc])

    //Explain to JaCoco where are our .class file
    classDirectories = files([debugTree])

    //Accumulate all test reports
    executionData = fileTree(dir: "$buildDir", includes: [
            "jacoco/*.exec",                                    // Generated by JUnit tests 
            "outputs/code-coverage/connected/**/*coverage.ec"   // Generated by Android's instrumented tests
    ])
}

У меня вопрос: не может ли JaCoco создать отчет о покрытии для "android.uid.system"?

...