Android,JaCoco无法为“ android.uid.system”创建覆盖范围

时间:2019-01-17 14:56:40

标签: java android code-coverage jacoco

使用android:sharedUserId="android.uid.system"时,JaCoco无法为插装测试用例创建覆盖率报告。

但是,如果我将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"创建覆盖率报告吗?

0 个答案:

没有答案