将我的Android项目更新为API 28后,我的androidTest项目停止工作。由于android.test.ApplicationTestCase
不存在,因此发生了编译错误。
ApplicationTest.java看起来像这样:
import android.app.Application;
import android.test.ApplicationTestCase;
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
另一个线程的建议是在gradle文件中添加一行:
androidTestImplementation 'com.google.android:android-test:4.1.1.4'
此Android Studio找到android.test.ApplicationTestCase
类之后。但是在重建过程中,我又遇到了另一个错误:
Cause 1: java.util.concurrent.ExecutionException: java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class org.xmlpull.v1.XmlPullParser found in modules kxml2-2.3.0.jar (net.sf.kxml:kxml2:2.3.0) and xpp3-1.1.4c.jar (xpp3:xpp3:1.1.4c)
Duplicate class org.xmlpull.v1.XmlPullParserException found in modules kxml2-2.3.0.jar (net.sf.kxml:kxml2:2.3.0) and xpp3-1.1.4c.jar (xpp3:xpp3:1.1.4c)
Duplicate class org.xmlpull.v1.XmlPullParserFactory found in modules kxml2-2.3.0.jar (net.sf.kxml:kxml2:2.3.0) and xpp3-1.1.4c.jar (xpp3:xpp3:1.1.4c)
Duplicate class org.xmlpull.v1.XmlSerializer found in modules kxml2-2.3.0.jar (net.sf.kxml:kxml2:2.3.0) and xpp3-1.1.4c.jar (xpp3:xpp3:1.1.4c)
我的build.gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.myapp"
minSdkVersion 16
targetSdkVersion 28
versionCode 9
versionName "2.5"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'com.android.support:design:28.0.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.opencsv:opencsv:4.5'
testImplementation 'junit:junit:4.12'
testImplementation 'com.google.guava:guava:24.1-jre'
androidTestImplementation 'com.google.android:android-test:4.1.1.4'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support:support-annotations:28.0.0'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation("com.android.support.test.espresso:espresso-contrib:2.2.2") {
exclude module: 'recyclerview-v7'
exclude module: 'design'
exclude module: 'support-v4'
}
}
感谢您对此问题的帮助。
答案 0 :(得分:0)
您需要从xpp3
依赖项中排除com.google.android:android-test
依赖项组。
// app/build.gradle
androidTestImplementation('com.google.android:android-test:4.1.1.4') {
exclude group: 'xpp3', module: 'xpp3'
}
原因是已经在debugAndroidTest
构建变体的类路径中指定了它。感谢OneWorld's answer about checking the dependency graph。