我正在尝试在任何类型的 android 构建之前运行我的 react-native jest 测试。如果测试通过,那么我允许构建,如果没有,我会打印一条错误消息。我查找了 gradle 并且无法弄清楚如何配置我的不同构建类型来做到这一点。我试图开始向我的 build.gradle 文件添加一个非常简单的任务:
task runTests {
println 'runTests before build'
}
和一个
tasks.assembleDebug.dependsOn runTests
但这只会使整个构建失败。这是我的 build.gradle 的样子:
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 23
defaultConfig {
applicationId "com.timeo"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
debug {
debuggable true
}
dev {
initWith debug
}
staging {
initWith debug
matchingFallbacks = ['debug']
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
implementation project(':react-native-config')
implementation project(':rn-fetch-blob')
implementation project(':react-native-file-opener')
implementation project(':react-native-fs')
implementation project(':react-native-document-picker')
implementation project(':react-native-svg')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:23.0.1"
implementation "com.facebook.react:react-native:+" // From node_modules
}
如何将 gradle 配置为仅在 jest 测试(npm 运行测试)通过时才构建?