android - 错误 : Program type already present: org. apache.maven.profiles.DefaultProfileManager

标签 android android-uiautomator

这是我的build.gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

apply plugin: 'org.jetbrains.dokka'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.me.daggersample"
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    flavorDimensions "version"
    productFlavors {
        production {
            dimension "version"
            minSdkVersion 17
        }
        uiTest {
            dimension "version"
            minSdkVersion 18
        }
    }
    compileOptions {
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    }

    dokka {
        outputFormat = 'html'
        outputDirectory = "$buildDir/javadoc"
    }
}

// To resolve //Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6
// https://stackoverflow.com/questions/48988778/cannot-inline-bytecode-built-with-jvm-target-1-8-into-bytecode-that-is-being-bui
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) {
    outputFormat = 'javadoc'
    outputDirectory = "$buildDir/javadoc"
}
configurations {
    androidTestImplementation.exclude module: 'guava'
    androidTestImplementation.exclude module: 'error_prone_annotations'
    androidTestImplementation.exclude module: 'checker-compat-qual'
    all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//    implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha02'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0-alpha02'
    implementation 'com.google.android.material:material:1.1.0-alpha04'

    //Navigation
    implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0-rc02'
    implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0-rc02'

    testImplementation 'org.mockito:mockito-inline:2.7.13'
    testImplementation 'com.nhaarman:mockito-kotlin-kt1.1:1.5.0'
    /*
        testImplementation 'org.robolectric:robolectric:4.0.2'
        testImplementation 'android.arch.core:core-testing:1.1.1'*/
    androidTestImplementation 'org.mockito:mockito-android:2.19.0'
    androidTestImplementation "org.robolectric:robolectric:4.2"
    androidTestImplementation 'androidx.test:core:' + rootProject.coreVersion
    androidTestImplementation 'androidx.test:core-ktx:' + rootProject.coreVersion
    androidTestImplementation 'androidx.test.ext:junit:' + rootProject.extJUnitVersion
    androidTestImplementation 'androidx.test.ext:junit-ktx:' + rootProject.extJUnitVersion
    androidTestImplementation 'androidx.test:runner:' + rootProject.runnerVersion
    androidTestImplementation 'androidx.test.espresso:espresso-core:' + rootProject.espressoVersion
    androidTestImplementation 'androidx.test.espresso:espresso-intents:' + rootProject.espressoVersion
    testImplementation 'junit:junit:4.12'
    // UiAutomator Testing
    androidTestImplementation 'androidx.test.uiautomator:uiautomator:' + rootProject.uiautomatorVersion;
    androidTestImplementation 'org.hamcrest:hamcrest-integration:1.3'


    implementation 'com.google.dagger:dagger-android:2.16'
    implementation 'com.google.dagger:dagger-android-support:2.16'
    kapt 'com.google.dagger:dagger-android-processor:2.16'
    kapt 'com.google.dagger:dagger-compiler:2.16'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
    implementation 'io.reactivex.rxjava2:rxjava:2.2.6'
    implementation 'io.reactivex.rxjava2:rxkotlin:2.3.0'
    implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0-alpha'
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
    implementation 'com.github.yongjhih.rx-mqtt:rx-mqtt-android:-SNAPSHOT'
//    implementation 'com.afollestad:aesthetic:1.0.0-beta05'

    implementation 'com.github.SherlockGougou:MagicIndicator:1.6.0'
    implementation 'com.patrickpissurno:ripple-effect:1.3.1'
}

该应用程序可以正常构建和运行,但是: 当我尝试运行我的 UI 自动化测试时,出现错误:

AGPBI: {"kind":"error","text":"Program type already present: org.apache.maven.profiles.ProfileManager","sources":[{}],"tool":"D8"}
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForProductionDebugAndroidTest'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
Program type already present: org.apache.maven.profiles.ProfileManager
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.

最佳答案

robolectric 依赖更改为

//Roboelectric
testImplementation ("org.robolectric:robolectric:$versions.robolectric"){
    exclude group: 'org.apache.maven'
}

关于android - 错误 : Program type already present: org. apache.maven.profiles.DefaultProfileManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55672937/

相关文章:

android - OnTouchListener 和 OnClickListener 的区别

android - 找不到 com.google.gms :google-services:4. 1.0

android - 在哪里放置 uiautomator 测试

java - isChecked() 方法是否已弃用

android - 使用Android Ui automator 2.0,如何获取ActivityName?

java - 如何在 Android 上设置选定日期前一天的通知

android - 从图库中选择照片后,我的 Android 应用程序关闭。 (帖子上有一个错误的视频)

android - RecyclerView 根本不更新

Android - 独立的 Fragment UI 测试工具

android - 如何检查 Intent ( Activity )的包名称(Espresso)中是否包含字符串?