16

Test running failed:

Permission Denial: starting instrumentation ComponentInfo{com.xxx.taskmanager.warehouse.tests/android.test.InstrumentationTestRunner} from pid=766, uid=766 not allowed because package com.xxx.taskmanager.warehouse.tests does not have a signature matching the target com.xxx.taskmanager.warehouse

Empty test suite.

This is my app.gradle file

apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'

android {
    signingConfigs {
        release
        {
            keyAlias 'xxx'
            keyPassword 'xxx'
            storeFile file('../keystore.jks')
            storePassword 'xxx'
        }
    }

    compileSdkVersion 16
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.xxx.taskmanager.warehouse"
        minSdkVersion 16
        targetSdkVersion 16
        versionCode 3
        versionName "3.0"
        testApplicationId "com.xxx.taskmanager.warehouse.tests"
    }

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

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

    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            output.outputFile = new File(
                    output.outputFile.parent,
                    "FLO_HANDHELD_V${variant.versionName}.apk"
            )
        }
    }

    variantFilter { variant ->
        if(variant.buildType.name.equals('debug')) {
            variant.setIgnore(true);
        }
    }

    productFlavors {
        production_b2b {
            applicationId "com.xxx.taskmanager.warehouse"
            minSdkVersion 16
            targetSdkVersion 16
            versionCode 3
            versionName "3.1-Prod-B2B"
        }
        stage_b2b {
            applicationId "com.xxx.taskmanager.warehouse"
            minSdkVersion 16
            targetSdkVersion 16
            versionCode 3
            versionName "3.1-Stage-B2B"
        }
        production_b2c {
            applicationId "com.xxx.taskmanager.warehouse"
            minSdkVersion 16
            targetSdkVersion 16
            versionCode 3
            versionName "3.1-Prod-B2C"
        }
        stage_b2c {
            applicationId "com.xxx.taskmanager.warehouse"
            minSdkVersion 16
            targetSdkVersion 16
            versionCode 3
            versionName "3.1-Stage-B2C"
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile files ('libs/android-support-v7-appcompat.jar')
    compile files('libs/android-support-v4.jar')
    compile project(':taskmanagerlib')
    compile files('libs/DataCollection.jar')
    androidTestCompile fileTree(dir: 'libs', include: 'robotium-solo-5.3.0.jar')
}

task copyTask(type: Copy) {
    from 'build/outputs/apk'
    into 'apks'
    exclude '**/*-unaligned.apk'
}

task deleteApk(type: org.gradle.api.tasks.Delete){
    //    delete 'apks'
}

task appBuild(dependsOn: ['deleteApk','clean', 'assembleRelease',       'copyTask']){
    assembleRelease.mustRunAfter deleteApk
    clean.mustRunAfter deleteApk
    copyTask.mustRunAfter assembleRelease
}

I think this error is happening because I have not declared the signingConfigs for test package. If so , how do I declare it. ?

Please help!!

Calos
  • 1,783
  • 19
  • 28
Rizwan_Khan
  • 313
  • 2
  • 10

5 Answers5

14

I have solved the issue. Answering it so that it can be useful for someone else.
Solution is for Android Studio :
For the tests to run , the build variant should be debug. Build Variants window is present in the left side of the android studio, if not activated then activate it by click on Build variants tab present on the left side of the android studio.

Rizwan_Khan
  • 313
  • 2
  • 10
2

You either have to change your build variant to debug, or add a testBuildType to your android tag inside your build.gradle file. Like this:

android {
    ...
    testBuildType "release"
}
LukeWaggoner
  • 8,869
  • 1
  • 29
  • 28
0
  1. Clean Your Project.

  2. Uninstall app if already install.

Now Run your project.

It's Completely Working for me.

Pinak Gauswami
  • 789
  • 6
  • 10
0

Had the same problem even with Android Studio 3.x years later. Previous answers did not work for me.

Only cure was to explicitly add the permissions to the test app on the phone.

Chris
  • 1,559
  • 1
  • 12
  • 6
0

It worked for me when changed Startapp code to use apk file instead of installed App. i.e. from :

From : return GetApp().InstalledApp(Settings.AUTPackageName).EnableLocalScreenshots().ConnectToApp();

To: return GetApp().ApkFile(Settings.AUTPath).EnableLocalScreenshots().ConnectToApp();

daksha
  • 1
  • 1