为什么Gradle connectedDebugAndroidTest依赖validateSigningRelease?

时间:2017-05-05 12:38:26

标签: android android-gradle android-keystore circleci

我正在设置Circle CI构建服务器以运行Android应用程序的检测测试,并且在运行connectedDebugAndroidTest Gradle任务时,会产生此故障:

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:validateSigningRelease'.
> Keystore file not set for signing config release

看起来让CircleCI上的发布签名工作有点棘手(没有将密钥库放在源代码控制器中,yuk)所以现在我的模块的构建文件中的发布配置是空白的:

signingConfigs {
    release {
    }
}

如果我在本地计算机上运行connectedDebugAndroidTest,它也会失败,但如果我之前运行的是assembleDebug则不行。即运行assembleDebug后跟connectedDebugAndroidTest在本地工作正常。

我已尝试在签名配置中提供虚拟发布签名详细信息,但任务是评估它们(供使用?),因此它们被拒绝。

如果要使用调试版本在设备上运行检测测试,为什么connectedDebugAndroidTest完全依赖于版本签名?

我是否遗漏了某些内容,或者是我在CI服务器上完全配置发布签名的唯一选择(密钥库通过Dropbox共享链接,yuk),因此它可以使用发布APK运行检测测试?

应用程序/的build.gradle:

apply plugin: 'com.android.application'

def versionMajor = 0
def versionMinor = 18
def versionPatch = 0
def versionBuild = 0 // bump for dogfood builds, public betas, etc.

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.myapp.android"
        minSdkVersion 14
        targetSdkVersion 25
        versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
        versionName "${versionMajor}.${versionMinor}.${versionPatch}"
        archivesBaseName = "MyApp v$versionName"  // Names APK e.g. MyApp-v1.2.3-release.apk
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        release {
            storeFile rootProject.file("my-app-keystore.jks")
            if (storeFile.exists()) {
                def config = new Properties()
                config.load(new FileInputStream(rootProject.file("my-app-keystore.passwords")))
                storePassword config.KeystorePassword
                keyAlias config.KeyAlias
                keyPassword config.KeyPassword
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
            testCoverageEnabled = true // Instrumentation only
        }
        debug {
            applicationIdSuffix ".debug" // App ID for debug builds has .debug suffix
            testCoverageEnabled = true // Instrumentation only
        }
    }

    dataBinding {
        enabled = true
    }

    lintOptions {
        disable 'ContentDescription', 'RtlHardcoded'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    // Copy release APK to project root
    task copyReleaseApk(type: Copy) {
        from 'build/outputs/apk'
        into '..'
        include '**/*release.apk'
    }

    afterEvaluate {
        if (tasks.findByPath("packageRelease") == null) {tasks.create("packageRelease")}
        tasks.findByPath("packageRelease").finalizedBy(copyReleaseApk)
    }

}

ext {
    // Single place to specify the support library version
    supportLibraryVersion = '25.3.1'
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'com.google.code.findbugs'
        exclude module: 'espresso-idling-resource'
//        exclude group: "javax.inject"
    })
    compile 'com.android.support.test.espresso:espresso-idling-resource:2.2.2'

    // Dagger dependency injection
    compile 'com.google.dagger:dagger:2.10'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.10'
    compile 'com.google.dagger:dagger-android:2.10'
    compile 'com.google.dagger:dagger-android-support:2.10'
    annotationProcessor 'com.google.dagger:dagger-android-processor:2.10'

    compile "com.android.support:appcompat-v7:$supportLibraryVersion"
    compile "com.android.support:design:$supportLibraryVersion"
    compile "com.android.support.constraint:constraint-layout:1.0.2"

    compile "com.jakewharton.timber:timber:4.5.1"
    compile "com.squareup.phrase:phrase:1.1.0"
    compile "com.squareup.retrofit2:retrofit:2.2.0"
    compile "com.squareup.retrofit2:converter-gson:2.2.0"
    compile "com.squareup.okhttp3:logging-interceptor:3.7.0"
    compile 'net.danlew:android.joda:2.9.9'

    testCompile 'junit:junit:4.12'
    compile 'com.google.firebase:firebase-crash:10.2.4'
    androidTestCompile 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'

的build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.4.0-alpha7'
        classpath 'com.google.gms:google-services:3.0.0'
        // Plugin to run test coverage report on unit tests (not instrumentation)
        classpath 'com.vanniktech:gradle-android-junit-jacoco-plugin:0.5.0'
    }
}

plugins {
    // Highlights dependencies on libraries where a newer version is available
    id 'com.github.ben-manes.versions' version '0.14.0'
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

// Configure dependencyUpdates task to look on release versions only, not beta etc
dependencyUpdates.resolutionStrategy = {
    componentSelection { rules ->
        rules.all { ComponentSelection selection ->
            boolean rejected = ['preview', 'alpha', 'beta', 'rc', 'cr'].any { qualifier ->
                selection.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/
            }
            if (rejected) {
                selection.reject('Release candidate')
            }
        }
    }
}

apply plugin: 'com.vanniktech.android.junit.jacoco'

0 个答案:

没有答案