我正在尝试将Detox集成到我们的React Native应用中进行测试。但是,在构建时出现错误:
Task :react-native-navigation:transformDexArchiveWithExternalLibsDexMergerForReactNative57_5DebugAndroidTest FAILED
D8: Program type already present: android.support.design.widget.CoordinatorLayout$Behavior
我已将相同版本的支持库强加到我的所有依赖项上。这是我的build.gradle:
configurations.all {
// OkHttp 3.5.0+ includes the websockets API, so we need this to prevent a conflict
// https://github.com/square/okhttp/issues/3040
// exclude module: 'okhttp-ws'
resolutionStrategy {
force "com.android.support:support-annotations:${rootProject.ext.supportLibVersion}"
force "com.android.support:support-v4:${rootProject.ext.supportLibVersion}"
force "com.android.support:support-v13:${rootProject.ext.supportLibVersion}"
force "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
force "com.android.support:recyclerview-v7:${rootProject.ext.supportLibVersion}"
force "com.android.support:design:${rootProject.ext.supportLibVersion}"
force "com.android.support:cardview-v7:${rootProject.ext.supportLibVersion}"
force "com.android.support:customtabs:${rootProject.ext.supportLibVersion}"
// force "com.google.android.gms:play-services-auth:${rootProject.ext.gmsVersion}"
// force "com.google.android.gms:play-services-base:${rootProject.ext.gmsVersion}"
// force "com.google.android.gms:play-services-basement:${rootProject.ext.gmsVersion}"
// force "com.google.android.gms:play-services-maps:${rootProject.ext.gmsVersion}"
// force "com.google.android.gms:play-services-location:${rootProject.ext.gmsVersion}"
// force "com.google.android.gms:play-services-gcm:${rootProject.ext.gmsVersion}"
// force "com.google.android.gms:play-services-iid:${rootProject.ext.gmsVersion}"
// force "com.google.android.gms:play-services-fitness:${rootProject.ext.gmsVersion}"
// force "com.google.android.gms:play-services-analytics:${rootProject.ext.gmsVersion}"
// force "com.google.android.gms:play-services-analytics-impl:${rootProject.ext.gmsVersion}"
// force "com.google.android.gms:play-services-tagmanager-v4-impl:${rootProject.ext.gmsVersion}"
// force "com.google.android.gms:play-services-tasks:${rootProject.ext.gmsVersion}"
// force "com.google.firebase:firebase-core:${rootProject.ext.gmsVersion}"
// force "com.google.firebase:firebase-config:${rootProject.ext.gmsVersion}"
// force "com.google.firebase:firebase-auth:${rootProject.ext.gmsVersion}"
// force "com.google.firebase:firebase-analytics:${rootProject.ext.gmsVersion}"
// force "com.google.firebase:firebase-analytics-impl:${rootProject.ext.gmsVersion}"
// force "com.google.firebase:firebase-database:${rootProject.ext.gmsVersion}"
// force "com.google.firebase:firebase-messaging:${rootProject.ext.gmsVersion}"
// force "com.google.firebase:firebase-storage:${rootProject.ext.gmsVersion}"
// force "com.google.firebase:firebase-crash:${rootProject.ext.gmsVersion}"
// force "com.google.firebase:firebase-iid:${rootProject.ext.gmsVersion}"
// force "com.google.firebase:firebase-common:${rootProject.ext.gmsVersion}"
// force 'com.squareup.okhttp3:okhttp:3.4.1'
// force 'com.squareup.okhttp3:okhttp:3.6.0'
// force 'com.squareup.okhttp3:okhttp:3.10.0'
}
}
dependencies {
implementation project(':react-native-contacts')
implementation project(':lottie-react-native')
implementation group: 'com.zendesk', name: 'support', version: '2.2.1'
implementation(project(':bugsnag-react-native')) {
exclude group: 'com.android.support'
}
implementation project(':react-native-cookies')
implementation(project(':react-native-google-signin')) {
exclude group: "com.google.android.gms"
}
implementation(project(':react-native-firebase')) {
transitive = false
}
implementation 'com.android.support:multidex:1.0.3'
// RNFirebase required dependencies
implementation('com.google.firebase:firebase-core:16.0.4') {
exclude group: 'com.google.firebase', module: 'firebase-analytics'
exclude group: 'com.google.firebase', module: 'firebase-measurement-connector-impl'
}
implementation("com.google.android.gms:play-services-base:16.0.1") {
exclude group: 'com.android.support'
}
implementation('com.google.firebase:firebase-messaging:17.3.4') {
exclude group: 'com.google.firebase', module: 'firebase-measurement-connector-impl'
}
// implementation(project(':react-native-camera')) {
// exclude group: 'com.android.support', module: 'cardview'
// exclude group: "com.google.android.gms"
// }
implementation project(':react-native-code-push')
// implementation(project(':react-native-mauron85-background-geolocation')) {
// exclude group: 'com.android.support', module: 'cardview'
// }
// For WebP support, including animated WebP
// implementation 'com.facebook.fresco:animated-webp:1.3.0'
implementation 'com.facebook.fresco:webpsupport:1.3.0'
implementation 'com.facebook.android:facebook-core:[4,5)'
implementation project(':react-native-uuid-generator')
implementation(project(':react-native-device-info')) {
exclude group: 'com.google.android.gms'
}
implementation project(':react-native-linear-gradient')
implementation(project(':react-native-sqlite-storage')) {
exclude group: 'com.android.support'
}
implementation(project(':react-native-secure-key-store')) {
exclude group: 'com.android.support'
}
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:design:${rootProject.ext.supportLibVersion}"
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation(project(':react-native-navigation')) {
exclude group: 'com.android.support'
}
implementation(project(':react-native-geolocation-service')) {
exclude group: 'com.google.android.gms'
exclude group: 'com.android.support'
}
implementation(project(":rncamerakit")) {
exclude group: 'com.android.support'
}
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.amplitude:android-sdk:2.19.1' // native sdk of amplitude
implementation project(':react-native-amplitude-analytics') // our react-native module
androidTestImplementation(project(path: ":detox")) {
exclude group: 'com.android.support'
}
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
}
这在项目的build.gradle中:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlinVersion = '1.3.11'
repositories {
google()
mavenLocal()
mavenCentral()
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.google.gms:google-services:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
url 'https://maven.google.com'
}
maven { url 'https://jitpack.io' }
repositories {
maven { url 'https://zendesk.jfrog.io/zendesk/repo' }
}
}
}
ext {
// buildToolsVersion = "23.0.3" // try 26.0.3?
buildToolsVersion = "28.0.3"
minSdkVersion = 19
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
gmsVersion = "15.0.0"
}
subprojects { subproject ->
afterEvaluate {
if ((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
variantFilter { variant ->
def names = variant.flavors*.name
if (names.contains("reactNative51") || names.contains("reactNative55") || names.contains("reactNative56") || names.contains("reactNative57") || names.contains("minReactNative44")) {
setIgnore(true)
}
}
}
}
}
}
Gradle版本设置为4.10:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
我也运行过app:dependencies,但是看不到支持设计可能在两个版本中使用过。