我正在使用Android Studio 3.3。并且我的Android应用可以构建并正常运行,但是当我尝试运行 Espresso 测试用例时,它无法构建。我正在使用AS 3.3。 生成错误日志表明这是由于:合并dex存档时, 我不确定如何解决此问题?
请帮助!
构建Espresso测试用例时的构建错误:
java.lang.RuntimeException: com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: enter code here
build.gradle(项目):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath "io.realm:realm-gradle-plugin:4.3.1"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(模块:应用程序):
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.innovapost.scq"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
lintOptions {
abortOnError false
}
buildTypes {
debug {
minifyEnabled = false
proguardFile 'proguard-rules.pro'
debuggable true
testCoverageEnabled false
}
release {
minifyEnabled = false
proguardFile 'proguard-rules.pro'
debuggable false
testCoverageEnabled false
//signingConfig signingConfigs.release
}
}
sourceSets {
main {
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
}
}
flavorDimensions "default"
productFlavors {
emulator {
manifestPlaceholders = [restServiceEndPoint : "https://nonprod-soa-gw-01.cpggpc.ca/staging%s/scq-operations/",
restServiceUsr : getProjectProperty("RestUsr.Stg"),
restServicePwd : getProjectProperty("RestPwd.Stg"),
dpServiceEndPoint : "https://nonprod-soa-gw-01.cpggpc.ca/staging%s/",
dpServiceUsr : getProjectProperty("DpUsr.Stg"),
dpServicePwd : getProjectProperty("DpPwd.Stg"),
environment : "EMULATOR",
validateHttpsCertificates: false]
}
dev {
manifestPlaceholders = [restServiceEndPoint : "https://nonprod-soa-gw-01.cpggpc.ca/staging%s/scq-operations/",
restServiceUsr : getProjectProperty("RestUsr.Dev"),
restServicePwd : getProjectProperty("RestPwd.Dev"),
dpServiceEndPoint : "https://nonprod-soa-gw-01.cpggpc.ca/integration%s/",
dpServiceUsr : getProjectProperty("DpUsr.Dev"),
dpServicePwd : getProjectProperty("DpPwd.Dev"),
environment : "DEV",
validateHttpsCertificates: false]
}
stg {
manifestPlaceholders = [restServiceEndPoint : "https://nonprod-soa-gw-01.cpggpc.ca/development%s/scq-operations/",
restServiceUsr : getProjectProperty("RestUsr.Stg"),
restServicePwd : getProjectProperty("RestPwd.Stg"),
dpServiceEndPoint : "https://nonprod-soa-gw-01.cpggpc.ca/development%s/",
dpServiceUsr : getProjectProperty("DpUsr.Stg"),
dpServicePwd : getProjectProperty("DpPwd.Stg"),
environment : "STG",
validateHttpsCertificates: false]
}
stgSecure {
manifestPlaceholders = [restServiceEndPoint: "https://nonprod-soa-gw-01.cpggpc.ca/development%s/scq-operations/",
restServiceUsr : getProjectProperty("RestUsr.Stg"),
restServicePwd : getProjectProperty("RestPwd.Stg"),
dpServiceEndPoint : "https://nonprod-soa-gw-01.cpggpc.ca/staging%s/",
dpServiceUsr : getProjectProperty("DpUsr.Stg"),
dpServicePwd : getProjectProperty("DpPwd.Stg"),
environment : "STG"]
}
}
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
//testCompile 'org.mockito:mockito-core:2.+'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
// Modules
compileOnly fileTree(include: ['com.symbol.emdk.jar'], dir: '../ScanLibrary/libs')
implementation project(':ApplicationLoggingLibrary')
implementation project(':ScanLibrary')
implementation project(':NetworkLibrary')
// Support libraries
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
// ViewModel and LiveData
implementation 'android.arch.lifecycle:extensions:1.1.1'
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
// Dependency Injection
implementation 'com.google.dagger:dagger:2.16'
implementation 'com.google.dagger:dagger-android-support:2.16'
testImplementation 'junit:junit:4.12'
annotationProcessor 'com.google.dagger:dagger-compiler:2.16'
annotationProcessor "com.google.dagger:dagger-android-processor:2.16"
androidTestImplementation 'org.powermock:powermock-api-mockito:1.6.4'
androidTestImplementation 'org.powermock:powermock-module-junit4-rule-agent:1.6.4'
androidTestImplementation 'org.powermock:powermock-module-junit4-rule:1.6.4'
androidTestImplementation 'org.powermock:powermock-module-junit4:1.6.4'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
implementation('commons-validator:commons-validator:1.4.1') {
exclude group: 'commons-collections', module: 'commons-collections'
}
}
def getProjectProperty(String property) {
if (project.hasProperty(property)) {
//println property + ": " + "${getProperty(property)}"
return "${getProperty(property)}"
} else {
println "getProjectProperty(): Couldn't find property " + property
return ""
}
}