首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android测试-升级到API 28后复制类

Android测试-升级到API 28后复制类
EN

Stack Overflow用户
提问于 2019-06-19 06:05:36
回答 1查看 1.2K关注 0票数 3

在我的安卓项目更新到API28之后,我的androidTest项目停止了工作。由于android.test.ApplicationTestCase不存在,因此出现编译错误。

ApplicationTest.java看起来像这样:

代码语言:javascript
复制
import android.app.Application;
import android.test.ApplicationTestCase;

public class ApplicationTest extends ApplicationTestCase<Application> {
    public ApplicationTest() {
        super(Application.class);
    }
}

另一个帖子的建议是在gradle文件中添加一行:

代码语言:javascript
复制
androidTestImplementation 'com.google.android:android-test:4.1.1.4'

此后,Android Studio创建了android.test.ApplicationTestCase类。但是在重建过程中,我得到了另一个错误:

代码语言:javascript
复制
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文件:

代码语言:javascript
复制
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'
    }
}
EN

回答 1

Stack Overflow用户

发布于 2019-08-20 03:13:29

需要从com.google.android:android-test依赖项中排除xpp3依赖项组。

代码语言:javascript
复制
// 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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56657635

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档